Adding
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
public class AuctionAssignment
|
||||
{
|
||||
[StringLength(4)] public string AuctionID { get; set; }
|
||||
public string PickupDate { get; set; }
|
||||
public string LegalSaleDate { get; set; }
|
||||
public string PickupOrDropOffNote { get; set; }
|
||||
public int? CleaningLevelRequested { get; set; }
|
||||
}
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
public class AutoImsWebService : IAutoImsWebService
|
||||
{
|
||||
private string URL = "https://wstls.autoims.com/ClientWebservice?clientId={0}";
|
||||
private readonly AutoImsServiceConfig _config;
|
||||
|
||||
public AutoImsWebService(AutoImsServiceConfig config)
|
||||
{
|
||||
_config = config;
|
||||
URL = string.Format(URL, config.ClientId);
|
||||
}
|
||||
|
||||
public static string GetFormattedVIN(string vin)
|
||||
{
|
||||
return vin.Trim().PadLeft(17, '0').ToUpper();
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> RemoveFromAuction(string vin, string clientStockNumber)
|
||||
{
|
||||
WebServiceResponse webServiceResponse = null;
|
||||
|
||||
URL = string.Format(URL + "&vin={0}&clientStockNum={1}", vin, clientStockNumber);
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
using (var req = new HttpRequestMessage(HttpMethod.Delete, URL))
|
||||
{
|
||||
string authInfo = String.Format("{0}:{1}", _config.Login, _config.Password);
|
||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
||||
req.Headers.Add("Authorization", "Basic " + authInfo);
|
||||
req.Headers.Remove("Expect");
|
||||
req.Headers.Add("Expect", "");
|
||||
|
||||
using (HttpResponseMessage resp = await client.SendAsync(req))
|
||||
{
|
||||
//resp.EnsureSuccessStatusCode();
|
||||
|
||||
var cont = await resp.Content.ReadAsStringAsync();
|
||||
webServiceResponse = DeserializeResponse<WebServiceResponse>(cont);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return webServiceResponse;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> PostVehicleAsync<T>(T vehicle)
|
||||
{
|
||||
var xml = Serialize<T>(vehicle);
|
||||
WebServiceResponse WebServiceResponse = null;
|
||||
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
using (var content = new StringContent(xml))
|
||||
{
|
||||
content.Headers.Remove("Content-Type");
|
||||
content.Headers.Add("Content-Type", "application/xml");
|
||||
|
||||
using (var req = new HttpRequestMessage(HttpMethod.Post, URL))
|
||||
{
|
||||
string authInfo = String.Format("{0}:{1}", _config.Login, _config.Password);
|
||||
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
|
||||
req.Headers.Add("Authorization", "Basic " + authInfo);
|
||||
req.Headers.Remove("Expect");
|
||||
req.Headers.Add("Expect", "");
|
||||
req.Content = content;
|
||||
|
||||
using (HttpResponseMessage resp = await client.SendAsync(req))
|
||||
{
|
||||
var cont = await resp.Content.ReadAsStringAsync();
|
||||
WebServiceResponse = DeserializeResponse<WebServiceResponse>(cont);
|
||||
|
||||
// 6 is duplicate.
|
||||
if (WebServiceResponse.Status.Code == 6)
|
||||
{
|
||||
Log.Information($"Auto Ims Status Code: { WebServiceResponse.Status.Code}, {WebServiceResponse.Status.Description}");
|
||||
WebServiceResponse.Status.Code = 1;
|
||||
WebServiceResponse.Status.Description = "Notification Already Sent To AutoIMS";
|
||||
}
|
||||
else if (WebServiceResponse.Status.Code != 1)
|
||||
{
|
||||
throw new Exception("Auto Ims Status Code: " + WebServiceResponse.Status.Code + " " + string.Join(",",
|
||||
WebServiceResponse.Status.ValidationError.Select(x =>
|
||||
x.Message)));
|
||||
}
|
||||
|
||||
//resp.EnsureSuccessStatusCode();
|
||||
if (resp.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
throw new Exception("Status Code: " + resp.StatusCode + " " + string.Join(",",
|
||||
WebServiceResponse.Status.ValidationError.Select(x =>
|
||||
x.Message)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return WebServiceResponse;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> UpdateAuctionIdentifyingValuesAsync(string customerNum,
|
||||
string vin,
|
||||
string auctionAssignmentId)
|
||||
{
|
||||
VehicleIdentiferUpdate veh = new VehicleIdentiferUpdate();
|
||||
veh.ClientAccountNumber = customerNum;
|
||||
veh.VIN = vin;
|
||||
veh.ClientField1 = auctionAssignmentId;
|
||||
|
||||
var response = await PostVehicleAsync<VehicleIdentiferUpdate>(veh);
|
||||
response.AuctionCollateralVin = vin;
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> AddAuctionNote(string vin, string customerNumber, string note,
|
||||
string writer)
|
||||
{
|
||||
WebServiceResponse response = null;
|
||||
VehicleNote vehicle = new VehicleNote();
|
||||
vehicle.VIN = vin;
|
||||
|
||||
//do not include and AutoIMS will timestamp.
|
||||
//vehicle.Note.CreationDate = String.Empty;// DateTime.Now.ToString("yyyy-MM-dd");
|
||||
vehicle.Note.NoteText = note;
|
||||
vehicle.Note.Writer = writer;
|
||||
vehicle.Note.Private = false;
|
||||
|
||||
response = await PostVehicleAsync<VehicleNote>(vehicle);
|
||||
response.AuctionCollateralVin = vin;
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> RemoveAuction(string VIN, string customerNumber)
|
||||
{
|
||||
WebServiceResponse response = await RemoveFromAuction(VIN, customerNumber);
|
||||
response.AuctionCollateralVin = VIN;
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> Redeem(string VIN)
|
||||
{
|
||||
WebServiceResponse response = null;
|
||||
RedeemVehicle vehicle = new RedeemVehicle();
|
||||
vehicle.VIN = VIN;
|
||||
vehicle.AuctionAssignment.RedeemVehicle = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
response = await PostVehicleAsync<RedeemVehicle>(vehicle);
|
||||
response.AuctionCollateralVin = VIN;
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> TitleSent(string VIN)
|
||||
{
|
||||
WebServiceResponse response = null;
|
||||
VehicleTitleSent vehicle = new VehicleTitleSent();
|
||||
vehicle.VIN = VIN;
|
||||
vehicle.AuctionAssignment.TitleSent = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
response = await PostVehicleAsync<VehicleTitleSent>(vehicle);
|
||||
response.AuctionCollateralVin = VIN;
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WebServiceResponse> PlaceHold(string VIN, int holdCode, DateTime holdUntil)
|
||||
{
|
||||
WebServiceResponse response = null;
|
||||
VehicleHold vehicle = new VehicleHold();
|
||||
vehicle.VIN = VIN;
|
||||
vehicle.AuctionAssignment.SaleHold.HoldUntil = holdUntil.ToString("yyyy-MM-dd");
|
||||
vehicle.AuctionAssignment.SaleHold.HoldStatus = holdCode;
|
||||
|
||||
response = await PostVehicleAsync<VehicleHold>(vehicle);
|
||||
response.AuctionCollateralVin = VIN;
|
||||
return response;
|
||||
}
|
||||
|
||||
public string GetCollateralImage(string conditionReporUrl)
|
||||
{
|
||||
string html = String.Empty;
|
||||
string imageLink = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
var response = client.GetAsync(conditionReporUrl).Result;
|
||||
|
||||
html = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var aTag = html.Substring(html.IndexOf("pic_0", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
var imgTag = aTag.Substring(aTag.IndexOf("addpic(", StringComparison.OrdinalIgnoreCase) + 7);
|
||||
|
||||
//var src = imgTag.Substring(imgTag.IndexOf("src=\"", StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
imageLink = imgTag.Substring(0, imgTag.IndexOf(",", StringComparison.OrdinalIgnoreCase))
|
||||
.Replace("'", "").Replace("\"", "");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
imageLink = null;
|
||||
}
|
||||
|
||||
return imageLink;
|
||||
}
|
||||
|
||||
private static string Serialize<T>(T vehicle)
|
||||
{
|
||||
XmlSerializer xsSubmit = new XmlSerializer(typeof(T));
|
||||
|
||||
string xml = "";
|
||||
|
||||
using (var sww = new StringWriter())
|
||||
{
|
||||
using (XmlWriter writer = XmlWriter.Create(sww))
|
||||
{
|
||||
xsSubmit.Serialize(writer, vehicle);
|
||||
xml = sww.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
private T DeserializeResponse<T>(string xml)
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(StringToByteArrayUtf8(xml)))
|
||||
{
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
|
||||
|
||||
using (StreamReader xmlStreamReader = new StreamReader(memoryStream, Encoding.UTF8))
|
||||
{
|
||||
return (T) xmlSerializer.Deserialize(xmlStreamReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] StringToByteArrayUtf8(string value)
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
public class AutoImsServiceConfig
|
||||
{
|
||||
public string URL { get; set; }
|
||||
public string Login { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
public interface IAutoImsWebService
|
||||
{
|
||||
Task<WebServiceResponse> RemoveFromAuction(string vin, string clientStockNumber);
|
||||
Task<WebServiceResponse> PostVehicleAsync<T>(T vehicle);
|
||||
|
||||
Task<WebServiceResponse> UpdateAuctionIdentifyingValuesAsync( string customerNum,
|
||||
string vin,
|
||||
string auctionAssignmentId);
|
||||
|
||||
Task<WebServiceResponse> AddAuctionNote(string vin, string customerNumber, string note, string writer);
|
||||
Task<WebServiceResponse> RemoveAuction(string VIN, string customerNumber);
|
||||
Task<WebServiceResponse> Redeem(string VIN);
|
||||
Task<WebServiceResponse> TitleSent(string VIN);
|
||||
Task<WebServiceResponse> PlaceHold(string VIN, int holdCode, DateTime holdUntil);
|
||||
string GetCollateralImage(string conditionReporUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class VehicleNote
|
||||
{
|
||||
public VehicleNote()
|
||||
{
|
||||
Note = new Note();
|
||||
}
|
||||
|
||||
public string VIN { get; set; }
|
||||
public Note Note { get; set; }
|
||||
}
|
||||
|
||||
public class Note
|
||||
{
|
||||
// [MaxLength(25)]
|
||||
public string Writer { get; set; }
|
||||
|
||||
// public string CreationDate { get; set; }
|
||||
// [MaxLength(255)]
|
||||
public string NoteText { get; set; }
|
||||
public bool Private { get; set; }
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class RedeemVehicle
|
||||
{
|
||||
public RedeemVehicle()
|
||||
{
|
||||
AuctionAssignment = new RedeemAuctionAssignment();
|
||||
}
|
||||
|
||||
public string VIN { get; set; }
|
||||
public RedeemAuctionAssignment AuctionAssignment { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "AuctionAssignment")]
|
||||
public class RedeemAuctionAssignment
|
||||
{
|
||||
/*If set, vehicle is considered 'redeemed' and
|
||||
will not be sold. Vehicle record will be
|
||||
archived after designated period of time
|
||||
(consignor specific)*/
|
||||
public string RedeemVehicle { get; set; }
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class FloorPriceVehicle
|
||||
{
|
||||
public FloorPriceVehicle()
|
||||
{
|
||||
AuctionAssignment = new FloorPriceAuctionAssignment();
|
||||
}
|
||||
|
||||
public string ClientAccountNumber { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public FloorPriceAuctionAssignment AuctionAssignment { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "AuctionAssignment")]
|
||||
public class FloorPriceAuctionAssignment
|
||||
{
|
||||
public decimal FloorPrice { get; set; }
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class Vehicle
|
||||
{
|
||||
public Vehicle()
|
||||
{
|
||||
AuctionAssignment = new AuctionAssignment();
|
||||
VehicleLocation = new VehicleLocation();
|
||||
}
|
||||
|
||||
[MaxLength(25)] public string ClientAccountNumber { get; set; }
|
||||
[StringLength(17)] public string VIN { get; set; }
|
||||
[MaxLength(30)] public string Make { get; set; }
|
||||
[MaxLength(30)] public string Model { get; set; }
|
||||
public int ModelYear { get; set; }
|
||||
[MaxLength(4)] public string BodyStyle { get; set; }
|
||||
public int Classification { get; set; }
|
||||
|
||||
|
||||
public string ClientField1 { get; set; }
|
||||
|
||||
public bool VehicleIsOperable { get; set; }
|
||||
|
||||
public AuctionAssignment AuctionAssignment { get; set; }
|
||||
public VehicleLocation VehicleLocation { get; set; }
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class VehicleHold
|
||||
{
|
||||
public VehicleHold()
|
||||
{
|
||||
AuctionAssignment = new HoldAuctionAssignment();
|
||||
}
|
||||
|
||||
public string VIN { get; set; }
|
||||
public HoldAuctionAssignment AuctionAssignment { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "AuctionAssignment")]
|
||||
public class HoldAuctionAssignment
|
||||
{
|
||||
public HoldAuctionAssignment()
|
||||
{
|
||||
SaleHold = new SaleHold();
|
||||
}
|
||||
|
||||
public SaleHold SaleHold { get; set; }
|
||||
}
|
||||
|
||||
public class SaleHold
|
||||
{
|
||||
public int HoldStatus { get; set; }
|
||||
public string HoldUntil { get; set; }
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class VehicleIdentiferUpdate
|
||||
{
|
||||
[MaxLength(25)] public string ClientAccountNumber { get; set; }
|
||||
[StringLength(17)] public string VIN { get; set; }
|
||||
public string ClientField1 { get; set; }
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
public class VehicleLocation
|
||||
{
|
||||
public int Type { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string Name { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string Address { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string City { get; set; }
|
||||
[MaxLength(20)]
|
||||
public string State { get; set; }
|
||||
[MaxLength(20)]
|
||||
public string Zip { get; set; }
|
||||
|
||||
[MaxLength(30)]
|
||||
public string Phone { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
[XmlRoot(ElementName = "Vehicle", Namespace = "http://www.autoims.com/AutoIMSVehicle")]
|
||||
public class VehicleTitleSent
|
||||
{
|
||||
public VehicleTitleSent()
|
||||
{
|
||||
AuctionAssignment = new TitleSentAuctionAssignment();
|
||||
}
|
||||
|
||||
public string VIN { get; set; }
|
||||
public TitleSentAuctionAssignment AuctionAssignment { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot(ElementName = "AuctionAssignment")]
|
||||
public class TitleSentAuctionAssignment
|
||||
{
|
||||
public string TitleSent { get; set; }
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.AutoIMS
|
||||
{
|
||||
/// <remarks/>
|
||||
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
|
||||
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
|
||||
public partial class WebServiceResponse
|
||||
{
|
||||
public string AuctionCollateralVin { get; set; }
|
||||
private WebServiceResponseStatus statusField;
|
||||
|
||||
/// <remarks/>
|
||||
public WebServiceResponseStatus Status
|
||||
{
|
||||
get { return this.statusField; }
|
||||
set { this.statusField = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks/>
|
||||
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
|
||||
public partial class WebServiceResponseStatus
|
||||
{
|
||||
private int codeField;
|
||||
|
||||
private string descriptionField;
|
||||
|
||||
private WebServiceResponseStatusValidationError[] validationErrorField;
|
||||
|
||||
/// <remarks/>
|
||||
public int Code
|
||||
{
|
||||
get { return this.codeField; }
|
||||
set { this.codeField = value; }
|
||||
}
|
||||
|
||||
/// <remarks/>
|
||||
public string Description
|
||||
{
|
||||
get { return this.descriptionField; }
|
||||
set { this.descriptionField = value; }
|
||||
}
|
||||
|
||||
/// <remarks/>
|
||||
[System.Xml.Serialization.XmlElementAttribute("ValidationError")]
|
||||
public WebServiceResponseStatusValidationError[] ValidationError
|
||||
{
|
||||
get { return this.validationErrorField; }
|
||||
set { this.validationErrorField = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks/>
|
||||
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
|
||||
public partial class WebServiceResponseStatusValidationError
|
||||
{
|
||||
private string codeField;
|
||||
|
||||
private string messageField;
|
||||
|
||||
/// <remarks/>
|
||||
public string Code
|
||||
{
|
||||
get { return this.codeField; }
|
||||
set { this.codeField = value; }
|
||||
}
|
||||
|
||||
/// <remarks/>
|
||||
public string Message
|
||||
{
|
||||
get { return this.messageField; }
|
||||
set { this.messageField = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.NADA
|
||||
{
|
||||
public class CollateralValuation
|
||||
{
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Year { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string Uid { get; set; }
|
||||
public string UcgVehicleId { get; set; }
|
||||
public DateTime? LookupDate { get; set; }
|
||||
public string Mileage_Hours { get; set; }
|
||||
public int? MakeCode { get; set; }
|
||||
public string MakeDescription { get; set; }
|
||||
public int? SeriesCode { get; set; }
|
||||
public string SeriesDescription { get; set; }
|
||||
public int? BodyCode { get; set; }
|
||||
public string BodyDescription { get; set; }
|
||||
public int? Weight { get; set; }
|
||||
public decimal? Msrp { get; set; }
|
||||
public int? AveMileage { get; set; }
|
||||
public decimal? MileageAdjustment { get; set; }
|
||||
public bool AuctionInfoUnavailable { get; set; }
|
||||
public int LowAdjustedAuctionValue { get; set; }
|
||||
public int AverageAdjustedAuctionValue { get; set; }
|
||||
public int HighAdjustedAuctionValue { get; set; }
|
||||
public string DateRange { get; set; }
|
||||
public decimal Loan { get; set; }
|
||||
public decimal LoanPlusVinAcc { get; set; }
|
||||
public decimal LoanPlusVinAccMileage { get; set; }
|
||||
public decimal Retail { get; set; }
|
||||
public decimal RetailPlusVinAcc { get; set; }
|
||||
public decimal RetailPlusVinAccMileage { get; set; }
|
||||
public decimal AvgTradeIn { get; set; }
|
||||
public decimal AvgTradeInPlusVinAcc { get; set; }
|
||||
public decimal AvgTradeInPlusVinAccMileage { get; set; }
|
||||
public decimal RoughTradeIn { get; set; }
|
||||
public decimal RoughTradeInPlusVinAcc { get; set; }
|
||||
public decimal RoughTradeInPlusVinAccMileage { get; set; }
|
||||
public decimal TradeIn { get; set; }
|
||||
public decimal TradeInPlusVinAcc { get; set; }
|
||||
public decimal TradeInPlusVinAccMileage { get; set; }
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using JdpVehicle;
|
||||
using Serilog;
|
||||
using LCU.API.Internal.RepoApi.Repos.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
using LCU.API.Internal.RepoApi.Repos.Models.Results;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.NADA
|
||||
{
|
||||
public class CollateralValueService : ICollateralValueService
|
||||
{
|
||||
private readonly CollateralValueServiceConfig _config;
|
||||
private readonly IClientHelpers _clientHelpers;
|
||||
|
||||
public CollateralValueService(CollateralValueServiceConfig config, ClientHelpers clientHelpers)
|
||||
{
|
||||
_config = config;
|
||||
_clientHelpers = clientHelpers;
|
||||
}
|
||||
|
||||
|
||||
private readonly VehicleTypes[] _nadaVehicleType =
|
||||
{
|
||||
VehicleTypes.UsedCar,
|
||||
VehicleTypes.CommercialTruck
|
||||
};
|
||||
|
||||
public CollateralValuation GetCollateralValue(string vin,
|
||||
int mileage,
|
||||
int vehicleTypeKey)
|
||||
{
|
||||
var valueResponse = this.GetVehicleData(_config.Region, _config.Period, vin, vehicleTypeKey, mileage);
|
||||
|
||||
if (valueResponse != null)
|
||||
{
|
||||
var autoVehicle = new CollateralValuation()
|
||||
{
|
||||
Make = valueResponse.Make,
|
||||
Model = valueResponse.Body + " " + valueResponse.Model,
|
||||
Year = valueResponse.Modelyear,
|
||||
UcgVehicleId = valueResponse.Ucgvehicleid.ToString(), //ucgvehicleid is the new ID and not 1:1 to legacy UID
|
||||
SeriesDescription = valueResponse.Model,
|
||||
BodyDescription = valueResponse.Body,
|
||||
Weight = String.IsNullOrWhiteSpace(valueResponse.Curbweight) ? 0 : Int32.Parse(valueResponse.Curbweight),
|
||||
Msrp = String.IsNullOrWhiteSpace(valueResponse.Basemsrp) ? 0 : Int32.Parse(valueResponse.Basemsrp),
|
||||
AveMileage = valueResponse.Averagemileage,
|
||||
MileageAdjustment = valueResponse.Mileageadjustment,
|
||||
LookupDate = DateTime.Now,
|
||||
Loan = valueResponse.Baseloan,
|
||||
LoanPlusVinAccMileage = valueResponse.Adjustedloan,
|
||||
Retail = valueResponse.Basecleanretail,
|
||||
RetailPlusVinAccMileage = valueResponse.Adjustedcleanretail,
|
||||
AvgTradeIn = valueResponse.Baseaveragetrade,
|
||||
AvgTradeInPlusVinAccMileage = valueResponse.Adjustedaveragetrade,
|
||||
RoughTradeIn = valueResponse.Baseroughtrade,
|
||||
RoughTradeInPlusVinAccMileage = valueResponse.Adjustedroughtrade,
|
||||
TradeIn = valueResponse.Basecleantrade,
|
||||
TradeInPlusVinAccMileage = valueResponse.Adjustedcleantrade,
|
||||
AuctionInfoUnavailable = true
|
||||
};
|
||||
|
||||
//Try catch to prevent failure if no auction values available
|
||||
try
|
||||
{
|
||||
var auctionResponse = this.GetAuctionValues(_config.Period, valueResponse.Ucgvehicleid, _config.Region, vehicleTypeKey, vin, mileage);
|
||||
|
||||
if (auctionResponse != null)
|
||||
{
|
||||
autoVehicle.AuctionInfoUnavailable = false;
|
||||
autoVehicle.AverageAdjustedAuctionValue = auctionResponse.AvgAuction;
|
||||
autoVehicle.HighAdjustedAuctionValue = auctionResponse.HighAuction;
|
||||
autoVehicle.LowAdjustedAuctionValue = auctionResponse.LowAuction;
|
||||
autoVehicle.DateRange = auctionResponse.DateRange;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Failed to Retreive Auction Values in CollateralValueService");
|
||||
}
|
||||
|
||||
return autoVehicle;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private VehicleData GetVehicleData(int region, int period, string vin, int vehicleTypeKey, int mileage)
|
||||
{
|
||||
var newURL = string.Format(_config.DefaultVehicleAndValuesByVinEndpoint + "?period={0}&vin={1}®ion={2}&mileage={3}",
|
||||
period, vin, region, mileage);
|
||||
|
||||
var request = _clientHelpers.CreateGetHttpRequestMessage(newURL, _config.ApiKey);
|
||||
var response = _clientHelpers.SendHttpRequestMessage(request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception($"Request for vehicle data for vehicle with VIN {vin} was unsuccessful.");
|
||||
}
|
||||
|
||||
var content = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var result = JsonConvert.DeserializeObject<VehicleInformation>(content);
|
||||
|
||||
return result.Result[0];
|
||||
}
|
||||
|
||||
private AuctionData GetAuctionValues(int period, int ucgVehicleId, int region, int vehicleTypeKey, string vin, int mileage)
|
||||
{
|
||||
var newURL = string.Format(_config.WeeklyAuctionValuesByVehicleIdEndPoint + "?period={0}&vehicletype={1}&vin={2}&ucgvehicleid={3}®ion={4}&mileage={5}",
|
||||
period, this._nadaVehicleType[vehicleTypeKey], vin, ucgVehicleId, region, mileage);
|
||||
|
||||
var request = _clientHelpers.CreateGetHttpRequestMessage(newURL, _config.ApiKey);
|
||||
var response = _clientHelpers.SendHttpRequestMessage(request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception($"Request for auction data for vehicle with VIN {vin} was unsuccessful.");
|
||||
}
|
||||
|
||||
var content = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var result = JsonConvert.DeserializeObject<AuctionInformation>(content);
|
||||
|
||||
return result.Result[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.NADA
|
||||
{
|
||||
public class CollateralValueServiceConfig
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string LoginEndpoint { get; set; }
|
||||
public string VehicleEndpoint { get; set; }
|
||||
public string DefaultVehicleAndValuesByVinEndpoint { get; set; }
|
||||
public string WeeklyAuctionValuesByVehicleIdEndPoint { get; set; }
|
||||
public int Region { get; set; }
|
||||
public int Period { get; set; }
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
namespace LCU.API.Internal.RepoApi.Repos.WebServices.NADA
|
||||
{
|
||||
public interface ICollateralValueService
|
||||
{
|
||||
CollateralValuation GetCollateralValue(string vin,
|
||||
int mileage,
|
||||
int vehicleTypeKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user