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.
149 lines
5.9 KiB
149 lines
5.9 KiB
using Dapper;
|
|
using DealerSelection.Api.Infrastructure.Mulesoft;
|
|
using DealerSelection.Api.Models;
|
|
using DealerSelection.Api.Models.Enum;
|
|
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 UpdateDealerDetail(CustomerDealerInfoRequestDto dto)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
await cxn.ExecuteScalarAsync(Procedure.UpdateDealerDetails,
|
|
new
|
|
{
|
|
dto.BuId,
|
|
dto.RecordId,
|
|
dto.MobileNumber,
|
|
dto.DealerName,
|
|
dto.DealerCode,
|
|
dto.PinCode,
|
|
CustomerLat= dto.Latitude,
|
|
CustomerLong=dto.Longitude,
|
|
dto.DealerSelectionJobStatus,
|
|
dto.DealerSelectedMode
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"DS Repo:- 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)
|
|
{
|
|
_logger.LogInformation($"DS Repo:- GetCustomerData strated");
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
IEnumerable<MulesoftCustomerInfoDto> cusotmerInfo = await cxn.QueryAsync<MulesoftCustomerInfoDto>(Procedure.GetCustomerDataForJob,
|
|
new
|
|
{
|
|
buId,
|
|
recordId
|
|
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
return cusotmerInfo.ToList().FirstOrDefault();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"DS Repo :- Error at Repository:CustomerDetail in GetCustomerData for buId: {buId}.", ex.StackTrace);
|
|
throw new UnexpectedDataException($"Error at Repository:CustomerDetail in GetCustomerData for Request: ", ex);
|
|
}
|
|
}
|
|
|
|
public async Task<CustomerDto> IsDuplicateMobileNumber(int mobileNumber, string buName)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
IEnumerable<CustomerDto> cusotmerInfo = await cxn.QueryAsync<CustomerDto>(Procedure.IsDuplicateMobileNumber,
|
|
new
|
|
{
|
|
buName,
|
|
mobileNumber
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
return cusotmerInfo.ToList().FirstOrDefault();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"DS Repo:- 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<CustomerDto> GetCustomerDetailByBuCode(string mobileNumber, string buCode, string buSubType)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
IEnumerable<CustomerDto> cusotmerInfo = await cxn.QueryAsync<CustomerDto>(Procedure.GetCustomerDetailByBuCode,
|
|
new
|
|
{
|
|
buCode,
|
|
mobileNumber,
|
|
buSubType,
|
|
@DealerSelectionJobStatus=DealerSelectionJobStatus.SentToBot
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
return cusotmerInfo.ToList().FirstOrDefault();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"DS Repo:- Error at Repository:CustomerDetail in GetCustomerDetailByBuCode for MobileNumber: {mobileNumber}. ErrorMessage", ex.StackTrace);
|
|
throw new DuplicateException($"Error at Repository:CustomerDetail in GetCustomerDetailByBuCode for MobileNumber: {mobileNumber}.");
|
|
}
|
|
}
|
|
|
|
|
|
public async Task UpdateDealerSelectionJobStatus(int buId, int recordId, DealerSelectionJobStatus dealerSelectionJobStatus)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cxn = await OpenCxnAsync())
|
|
{
|
|
await cxn.ExecuteScalarAsync(Procedure.UpdateDealerSelectionJobStatus,
|
|
new
|
|
{
|
|
buId,
|
|
recordId,
|
|
dealerSelectionJobStatus
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"DS Repo:- Error at Repository:CustomerDetail in UpdateDealerSelectionJobStatus for BuId: {buId}, RecordId: {recordId}, DealerSelectionJobStatus: {dealerSelectionJobStatus}. ErrorMessage", ex.StackTrace);
|
|
throw new DuplicateException($"Error at Repository:CustomerDetail in UpdateDealerSelectionJobStatus for BuId: {buId}, RecordId: {recordId}, DealerSelectionJobStatus: {dealerSelectionJobStatus}");
|
|
}
|
|
}
|
|
|
|
}
|