using DealerSelection.Api.Models; using DealerSelection.Common.Data.Dapper; using Dapper; using Microsoft.Extensions.Logging; using System.Data; using System.Data.SqlClient; namespace DealerSelection.Api.Infrastructure.Mulesoft; public class Repository : RepositoryBaseDapperAsync, IRepository { private readonly ILogger _logger; public Repository(string cxnName, ILogger logger) : base(cxnName) { _logger = logger; } public async Task GetCustomerInfo(int buId, string bookingId) { try { using (SqlConnection cxn = await OpenCxnWithMappingAsync()) { IEnumerable cusotmerInfo = await cxn.QueryAsync(Procedure.GetCustomerInfoOnBookingId, new { buId, bookingId }, commandType: CommandType.StoredProcedure); return cusotmerInfo.ToList().FirstOrDefault(); } } catch (Exception ex) { _logger.LogError("BU:- " + buId.ToString() + " Error at Repository:Mulesoft in GetCustomerInfo." + ex.Message.ToString()); throw new UnexpectedDataException($"Error at Repository:Mulesoft in GetCustomerInfo for BuId: {buId} and BookingId: {bookingId}.", ex); } } public async Task UpdateMulesoftResponse(int buId, int recordId, string bookingId, string message, string isSuccessBooking, LeadData leadData) { try { using (SqlConnection cxn = await OpenCxnWithMappingAsync()) { await cxn.QueryAsync(Procedure.InsertLSQDetail, new { buId, recordId, bookingId, lead_Transferred = leadData.Lead_transferred, lead_Status = leadData.Lead_status, api_Request = message, api_Response = leadData.ApiResponse, lSQProspectId = leadData.Prospect_id, lSQOpportunityId = leadData.Opportunity_id, isSuccessBooking }, commandType: CommandType.StoredProcedure); } } catch (Exception ex) { _logger.LogError("BU:- " + buId.ToString() + $"Error at Repository:Mulesoft in UpdateMulesoftResponse for buId: {buId}, recordId: {recordId}, " + $"leadData.Lead_transferred: {leadData.Lead_transferred}, message: {message},leadData.ApiResponse: {leadData.ApiResponse}, " + $"leadData.Prospect_id:{leadData.Prospect_id}, leadData.Opportunity_id: {leadData.Opportunity_id}, " + $"isSuccessBooking: {isSuccessBooking} " + ex.Message.ToString()); throw new UnexpectedDataException($"Error at Repository:Mulesoft in UpdateMulesoftResponse for buId: {buId}, recordId: {recordId}, " + $"leadData.Lead_transferred: {leadData.Lead_transferred}, message: {message},leadData.ApiResponse: {leadData.ApiResponse}, " + $"leadData.Prospect_id:{leadData.Prospect_id}, leadData.Opportunity_id: {leadData.Opportunity_id}, " + $"isSuccessBooking: {isSuccessBooking} ", ex); } } public async Task InsertAndUpdateDealerRecord(DealerDetailDto dto) { try { using (SqlConnection cxn = await OpenCxnWithMappingAsync()) { await cxn.QueryAsync(Procedure.InsertUpdateDealerDetail, new { dto.BuId, dto.DealerCode, dto.Address1, dto.Address2, dto.City, dto.State, dto.Zip, dto.DisplayName, dto.ContactCard, dto.SalesPersonMail, dto.SaleMobileNumber, dto.EcomSalesAddress }, commandType: CommandType.StoredProcedure); } } catch (Exception ex) { _logger.LogError("BU:- " + dto.BuId.ToString() + " Error at Repository:Mulesoft in InsertAndUpdateDealerRecord for InfoBip Request: {dto.RequestDetail()}" + ex.Message.ToString()); throw new UnexpectedDataException($"Error at Repository:Mulesoft in InsertAndUpdateDealerRecord for InfoBip Request: {dto.RequestDetail()}", ex); } } public async Task> GetDataForLsqPush(int buId) { try { using (SqlConnection cxn = await OpenCxnAsync()) { IEnumerable lsqDto = await cxn.QueryAsync(Procedure.GetDataForLsqPush, new { buId }, commandType: CommandType.StoredProcedure); return lsqDto.ToList(); } } catch (Exception ex) { _logger.LogError("BU:- " + buId.ToString() + "Error at Repository:Mulesoft in GetDataForLsqPush " + ex.Message.ToString()); throw new UnexpectedDataException($"Error at Repository:Mulesoft in GetDataForLsqPush for BuId: {buId}.", ex); } } }