async public Task <ActionResult> Edit(long id, IFormCollection collection) { var productMapping = await _productMappingService.FindProductMapping(id).ConfigureAwait(false); if (productMapping == null) { return(NotFound()); } productMapping.Incoming = collection["Incoming"]; productMapping.Outgoing = collection["Outgoing"]; productMapping.Channelid = int.Parse(collection["Channelid"].ToString()); _productMappingService.UpdateProductMapping(productMapping); return(RedirectToAction(nameof(Index))); }
private async Task <string> GetProduct() { var mappingSettings = _settingService.LoadSetting <ProductMappingSettings>(); var allProductMapping = _productMappingService.GetAllProductMappingBySource((int)Source.Ebay); var tokenebay = EbayExtensions.GetToken(); foreach (var item in allProductMapping) { var product = _productService.GetProductById(item.ProductId); var clientapi = new HttpClient(); clientapi.BaseAddress = new Uri("https://api.ebay.com/"); clientapi.DefaultRequestHeaders.Clear(); clientapi.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); clientapi.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenebay); clientapi.Timeout = TimeSpan.FromMinutes(60); HttpResponseMessage Res = await clientapi.GetAsync("buy/browse/v1/item/" + item.ProductSourceId); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <ProductModelApi>(EmpResponse); var price = Convert.ToDecimal(result.price.value); if (price != item.Price) { var currencyService = EngineContext.Current.Resolve <ICurrencyService>(); product.Price = Round(currencyService.ConvertToPrimaryStoreCurrency(price * (1 + mappingSettings.AdditionalCostPercent / 100), currencyService.GetCurrencyByCode("USD")), -3); _productService.UpdateProduct(product); item.Price = price; _productMappingService.UpdateProductMapping(item); } } else if (Res.StatusCode == System.Net.HttpStatusCode.NotFound) { product.Deleted = true; _productService.UpdateProduct(product); } } return(null); }