public bool Publish(out List <string> publishDetails, BackgroundWorker bw = null) { publishDetails = new List <string>(); string apiKey = Settings.GetApiKey(); if (!string.IsNullOrEmpty(apiKey)) { var priceLevelRepo = new PriceLevelRepository(Settings.ConnectionString); var levelsToImport = priceLevelRepo.GetAll().ToList(); var existingLevels = WebServiceHelper.GetExistingPricingLevels(); var importCounter = 0; var existingCounter = 0; foreach (var level in levelsToImport) { if (existingLevels.Any(lvl => lvl.Name == level.Name)) { existingCounter++; continue; } var effectiveDate = level.EffectiveDate ?? DateTime.Now.ToUniversalTime(); if (level.EndDate < effectiveDate) { level.EndDate = null; } var request = new PricingLevelRequest { Name = level.Name, ExternalReference = level.ExternalReference, InventoryItems = new List <PricingLevelItemRequest>(), EffectiveDate = effectiveDate, EndDate = level.EndDate }; WebServiceHelper.PushPricingLevel(request); importCounter++; } publishDetails.Insert(0, $"{existingCounter} price levels already existing in LinkGreen and were not pushed."); publishDetails.Insert(0, $"{importCounter} price levels have been pushed to LinkGreen"); return(true); } Logger.Instance.Warning("No Api Key set while executing price level publish."); return(false); }
public static bool PushPricingLevel(PricingLevelRequest item) { var requestUrl = $"/SupplierInventoryService/rest/AddPricingLevel/{Key}"; var request = new RestRequest(requestUrl, Method.POST); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); var settings = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; var json = JsonConvert.SerializeObject(item, settings); request.AddParameter("application/json", json, null, ParameterType.RequestBody); var response = Client.Execute(request); return(response.StatusCode == HttpStatusCode.OK); }
public static bool PushPricingLevel(string pricingLevelName, PricingLevelItemRequest[] inventoryItems, DateTime effectiveDate, DateTime?endDate = null) { var requestUrl = $"/SupplierInventoryService/rest/AddPricingLevelItem/{Key}"; var request = new RestRequest(requestUrl, Method.POST); var body = new PricingLevelRequest { Name = pricingLevelName, EffectiveDate = effectiveDate, EndDate = null, InventoryItems = inventoryItems }; request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); var settings = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; var json = JsonConvert.SerializeObject(body, settings); request.AddParameter("application/json", json, null, ParameterType.RequestBody); var response = Client.Execute(request); if (response.StatusCode != HttpStatusCode.OK) { //lock (_debugLock) { // System.IO.File.AppendAllLines("C:\\temp\\publishlog.txt", // new[] {response.StatusCode + ":" + response.Content}); //} } return(response.StatusCode == HttpStatusCode.OK); }