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.
 
 
 

104 lines
4.4 KiB

using DealerSelection.Api.Infrastructure.YellowAI;
using DealerSelection.Api.Interface;
using DealerSelection.Api.Models;
using DealerSelection.Api.Models.Enum;
using DealerSelection.Common.Exceptions;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using CustomerDetailRepo = DealerSelection.Api.Infrastructure.CustomerDetail;
using MulesoftRepo = DealerSelection.Api.Infrastructure.Mulesoft;
namespace DealerSelection.Api;
public class YellowAIApi : IYellowAIApi
{
private readonly ILogger _logger;
private CustomerDetailRepo.IRepository CustomerDetailRepository { get; }
private IRepository Repository { get; }
private IMulesoftApi MulesoftApi { get; }
public YellowAIApi(CustomerDetailRepo.IRepository customerRepo, ILogger<YellowAIApi> logger, IMulesoftApi mulesoftApi, IRepository repository)
{
CustomerDetailRepository = customerRepo;
_logger = logger;
MulesoftApi = mulesoftApi;
Repository = repository;
}
public async Task UpdateSelectedDealer(CustomerDealerInfoRequest request)
{
_logger.LogInformation($"DS Api:-UpdateSelectedDealer Started :- MobileNumber {request.MobileNumber} BuCode {request.BuCode} BuSubType {request.BuSubType}" +
$"DealerCode {request.DealerCode} DealerName {request.DealerName} PinCode {request.PinCode} CustomerLat {request.Latitude} CustomerLong {request.Longitude} ");
try
{
if (IsValidData(request.MobileNumber, request.DealerCode, request.DealerName))
{
CustomerDetailRepo.CustomerDto customerinfo = await GetCustomerDetailByBuCode(request.MobileNumber, request.BuCode, request.BuSubType);
if (customerinfo != null)
{
MulesoftRepo.MulesoftCustomerInfoDto customerDetailInfo = await CustomerDetailRepository.GetCustomerData(customerinfo.BuId, customerinfo.RecordId);
customerDetailInfo.DealerCode = request.DealerCode;
customerDetailInfo.DealerName = request.DealerName;
customerDetailInfo.PinCode = request.PinCode;
customerDetailInfo.CustomerLat = request.Latitude;
customerDetailInfo.CustomerLong = request.Longitude;
customerDetailInfo.DealerSelectedMode = DealerSelectedMode.Bot.ToString();
await MulesoftApi.InsertLSQData(customerDetailInfo);
}
}
else
{
_logger.LogWarning($"Invalid data. Data Details: {request.RequestDetail()}.");
throw new ValidationException("Invalid data.");
}
}
catch(Exception ex)
{
_logger.LogError($"Some error occured: {ex.StackTrace}.");
throw new ValidationException($"Some error occured: {ex.StackTrace}.");
}
_logger.LogInformation($"DS Api:-UpdateSelectedDealer End :- MobileNumber {request.MobileNumber} BuCode {request.BuCode} BuSubType {request.BuSubType}" +
$"DealerCode {request.DealerCode} DealerName {request.DealerName} PinCode {request.PinCode} CustomerLat {request.Latitude} CustomerLong {request.Longitude} ");
}
public async Task<ModelDetail> GetModelDetails(string mobileNumber, string buCode, string buSubType)
{
_logger.LogInformation($"DS Api:-GetModelDetails Started :- MobileNumber {mobileNumber} BuCode {buCode} BuSubType {buSubType} ");
ModelDetailDto dto = await Repository.GetModelDetails(mobileNumber, buCode, buSubType);
ModelDetail response = null;
if (dto !=null)
{
response = new ModelDetail(dto.ModelCode);
}
_logger.LogInformation($"DS Api:-GetModelDetails End :- MobileNumber {mobileNumber} BuCode {buCode} BuSubType {buSubType} Response {response}");
return response;
}
#region Private Member
private static bool IsValidData(string mobileNumber, string dealerCode, string dealerName)
{
bool valid = Regex.IsMatch(mobileNumber, @"^[0-9]{10}$");
if (valid && string.IsNullOrWhiteSpace(dealerCode) && string.IsNullOrWhiteSpace(dealerName))
valid = false;
return valid;
}
private async Task<CustomerDetailRepo.CustomerDto> GetCustomerDetailByBuCode(string mobileNumber, string buCode,string buSubType)
{
return await CustomerDetailRepository.GetCustomerDetailByBuCode(mobileNumber, buCode, buSubType);
}
#endregion
}