You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

134 lines
5.6 KiB

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<Repository> logger) : base(cxnName)
{
_logger = logger;
}
public async Task<MulesoftCustomerInfoDto> GetCustomerInfo(int buId, string bookingId)
{
try
{
using (SqlConnection cxn = await OpenCxnWithMappingAsync<MulesoftCustomerInfoDto>())
{
IEnumerable<MulesoftCustomerInfoDto> cusotmerInfo = await cxn.QueryAsync<MulesoftCustomerInfoDto>(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<int>())
{
await cxn.QueryAsync<int>(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<int>())
{
await cxn.QueryAsync<int>(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<List<MulesoftCustomerInfoDto>> GetDataForLsqPush(int buId)
{
try
{
using (SqlConnection cxn = await OpenCxnAsync())
{
IEnumerable<MulesoftCustomerInfoDto> lsqDto = await cxn.QueryAsync<MulesoftCustomerInfoDto>(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);
}
}
}