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.
116 lines
4.5 KiB
116 lines
4.5 KiB
using Dapper;
|
|
using DealerSelection.Api.Infrastructure.Mulesoft;
|
|
using DealerSelection.Api.Models;
|
|
using DealerSelection.Common.Data.Dapper;
|
|
using DealerSelection.Common.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace DealerSelection.Api.Infrastructure.CustomerDetail;
|
|
|
|
public class Repository : RepositoryBaseDapperAsync, IRepository
|
|
{
|
|
private readonly ILogger _logger;
|
|
public Repository(string cxnName, ILogger<Repository> logger) : base(cxnName)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
|
|
public async Task<int> UpdateDealerDetail(CustomerDealerInfoRequestDto dto)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
int receivedBookingId = await cxn.ExecuteScalarAsync<int>(Procedure.UpdateDealerDetails,
|
|
new
|
|
{
|
|
dto.BuId,
|
|
dto.RecordId,
|
|
dto.MobileNumber,
|
|
dto.ModelCode,
|
|
dto.ModelName,
|
|
dto.ModelVariant,
|
|
dto.DealerName,
|
|
dto.DealerCode,
|
|
dto.PinCode,
|
|
dto.Latitude,
|
|
dto.Longitude,
|
|
dto.DealerSelectionJobStatus
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
return receivedBookingId;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"BU:- {dto.BuId}. Error at Repository:CustomerDetail in UpdateDealerDetail for Request: {dto.RequestDetail()}.", ex.StackTrace);
|
|
throw new UnexpectedDataException($"Error at Repository:CustomerDetail in UpdateDealerDetail for Request: {dto.RequestDetail()}.", ex);
|
|
}
|
|
}
|
|
|
|
public async Task<MulesoftCustomerInfoDto> GetCustomerData(int buId, int recordId)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
IEnumerable<MulesoftCustomerInfoDto> cusotmerInfo = await cxn.QueryAsync<MulesoftCustomerInfoDto>(Procedure.GetCustomerDataForJob,
|
|
commandType: CommandType.StoredProcedure);
|
|
return cusotmerInfo.ToList().FirstOrDefault();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("Error at Repository:CustomerDetail in UpdateDealerDetail for Request: {customerInfo.RequestDetail()}.", ex.StackTrace);
|
|
throw new UnexpectedDataException($"Error at Repository:CustomerDetail in UpdateDealerDetail for Request: ", ex);
|
|
}
|
|
}
|
|
|
|
public async Task<bool> IsDuplicateMobileNumber(int mobileNumber)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
bool isDuplicate = await cxn.QueryFirstAsync<bool>(Procedure.IsDuplicateMobileNumber,
|
|
new
|
|
{
|
|
mobileNumber
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
return isDuplicate;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"Error at Repository:CustomerDetail in IsDuplicateMobileNumber for MobileNumber: {mobileNumber}. ErrorMessage", ex.StackTrace);
|
|
throw new DuplicateException($"Error at Repository:CustomerDetail in IsDuplicateMobileNumber for MobileNumber: {mobileNumber}.");
|
|
}
|
|
}
|
|
|
|
|
|
public async Task UpdateDealerSelectionJobStatus(int buId, int recordId, int mobileNumber, DealerSelectionJobStatus dealerSelectionJobStatus)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
await cxn.QueryFirstAsync(Procedure.UpdateDealerSelectionJobStatus,
|
|
new
|
|
{
|
|
buId, recordId, mobileNumber, dealerSelectionJobStatus
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"Error at Repository:CustomerDetail in UpdateDealerSelectionJobStatus for BuId: {buId}, RecordId: {recordId}, MobileNumber: {mobileNumber}, DealerSelectionJobStatus: {dealerSelectionJobStatus}. ErrorMessage", ex.StackTrace);
|
|
throw new DuplicateException($"Error at Repository:CustomerDetail in UpdateDealerSelectionJobStatus for BuId: {buId}, RecordId: {recordId}, MobileNumber: {mobileNumber}, DealerSelectionJobStatus: {dealerSelectionJobStatus}");
|
|
}
|
|
}
|
|
|
|
}
|