This commit is contained in:
Zeeshaun
2026-03-13 09:27:34 -05:00
parent 256f579489
commit a675c5f5b0
381 changed files with 20992 additions and 0 deletions
@@ -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; }
}
}
@@ -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);
}
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
}