121 lines
4.8 KiB
C#
121 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Models.AutoIms;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Services.AutoIms
|
|
{
|
|
public class AutoImsAuctionProcessorService : IAutoImsAuctionProcessorService
|
|
{
|
|
private readonly IAuctionProcessorDao _auctionProcessorDao;
|
|
|
|
public AutoImsAuctionProcessorService(IAuctionProcessorDao auctionProcessorDao)
|
|
{
|
|
_auctionProcessorDao = auctionProcessorDao;
|
|
}
|
|
|
|
public ImportResultRow ImportSingleAutoImsAuction(ImsAutoFileData incomingAutoImsData)
|
|
{
|
|
AuctionAssignment auctionAssignment;
|
|
var result = new ImportResultRow()
|
|
{
|
|
Success = true,
|
|
Description = incomingAutoImsData.Description,
|
|
Messages = new List<string>()
|
|
};
|
|
|
|
incomingAutoImsData.VIN = incomingAutoImsData.VIN.Trim();
|
|
if (incomingAutoImsData.VIN.Length != 17) // must be 17. Auction may add as less than 17 characters.
|
|
{
|
|
Log.Error($"Vin Length Not Correct, {incomingAutoImsData.AuctionCustomerNo}, {incomingAutoImsData.VIN}, Skipping.");
|
|
result.Success = false;
|
|
result.Messages.Add("Invalid VIN, this row has been skipped.");
|
|
return result;
|
|
}
|
|
|
|
bool requiresAutoImsUpdate =
|
|
string.IsNullOrWhiteSpace(incomingAutoImsData.AuctionCustomerNo) ||
|
|
incomingAutoImsData.AuctionAssignmentId == 0;
|
|
|
|
try
|
|
{
|
|
result.RepoAccount = _auctionProcessorDao.FindRepoForImsAuctionItem(incomingAutoImsData);
|
|
auctionAssignment = _auctionProcessorDao.FindAuctionAssignment(incomingAutoImsData);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Messages.Add("Failed to load required data => " + ex.Message);
|
|
return result;
|
|
}
|
|
|
|
RepoAccount repo = result.RepoAccount;
|
|
// Always re-assign these fields, carried from previous system.
|
|
incomingAutoImsData.RepoId = auctionAssignment.RepoId ?? 0;
|
|
incomingAutoImsData.AuctionCustomerNo = auctionAssignment.AuctionCustomerNo;
|
|
incomingAutoImsData.AuctionAssignmentId = auctionAssignment.ID;
|
|
|
|
ImsAutoFileData existingAuctionFile = auctionAssignment.AutoIMS;
|
|
if (existingAuctionFile == null)
|
|
{
|
|
existingAuctionFile = _auctionProcessorDao.FindImsAuctionFileData(auctionAssignment.ID,
|
|
incomingAutoImsData.AuctionCustomerNo,
|
|
incomingAutoImsData.VIN);
|
|
}
|
|
|
|
if (existingAuctionFile == null)
|
|
{
|
|
result.Messages.Add("New Entry Created.");
|
|
existingAuctionFile = _auctionProcessorDao.CreateImsAuctionFileData(incomingAutoImsData);
|
|
if (existingAuctionFile.AssignmentAccepted != null)
|
|
{
|
|
result.Messages.Add("Auction accepted by Auto IMS on " + existingAuctionFile.AssignmentAccepted);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.Messages.Add("Updated existing IMS Auction Entry.");
|
|
existingAuctionFile = _auctionProcessorDao.UpdateExistingFile(existingAuctionFile, incomingAutoImsData);
|
|
}
|
|
|
|
result = CheckAuctionGates(existingAuctionFile, result);
|
|
|
|
// update autoims with customer number and auction assignment id when not added through our interface.
|
|
if (requiresAutoImsUpdate)
|
|
{
|
|
result.Messages.Add(
|
|
_auctionProcessorDao.UpdateAutoImsFromAuctionData(existingAuctionFile));
|
|
}
|
|
|
|
result.Data = existingAuctionFile;
|
|
return result;
|
|
}
|
|
|
|
public ImportResultRow CheckAuctionGates(ImsAutoFileData existingAuctionFile, ImportResultRow result)
|
|
{
|
|
if (existingAuctionFile.VehicleGrade > 0)
|
|
{
|
|
result.Messages.Add("Grade present: " + existingAuctionFile.VehicleGrade + ".");
|
|
}
|
|
|
|
if (existingAuctionFile.FloorPriceAccepted > 0)
|
|
{
|
|
result.Messages.Add("Accepted Floor Price present: $" +
|
|
existingAuctionFile.FloorPriceAccepted + ".");
|
|
}
|
|
|
|
if (existingAuctionFile.SoldDate != null)
|
|
{
|
|
result.Messages.Add("Auction Sold:" + existingAuctionFile.SoldDate + ".");
|
|
}
|
|
|
|
if (existingAuctionFile.FundsSent != null)
|
|
{
|
|
result.Messages.Add("Funds Send Date received: " + existingAuctionFile.FundsSent + ".");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |