public HttpStatusCode Post(Guid apikey, [FromBody] MerchantProductUpdateRequest request) { try { if (request == null) { return(HttpStatusCode.BadRequest); } MerchantProductUpdateRequestService merchServ = new MerchantProductUpdateRequestService(); bool productUpdated = merchServ.UpdateProduct(apikey, request); if (productUpdated) { return(HttpStatusCode.OK); } else { return(HttpStatusCode.InternalServerError); } } catch (Exception e) { return(HttpStatusCode.InternalServerError); } }
public bool UpdateProduct(Guid apikey, MerchantProductUpdateRequest request) { MerchantProductUpdateRequestRepository merchRepo = new MerchantProductUpdateRequestRepository(); foreach (var sku in request.Skus) { string productId; //hämta merchantid genom apikey från SQL-databas var merchantRepo = new MerchantSqlRepository(); var merchant = merchantRepo.GetByApiKey(apikey); if (merchant == null) { return(false); //throw new NullReferenceException($"merchant with apikey: {apikey} is missing!"); } string merchantId = merchant.MerchantId.ToString().ToLowerInvariant(); //hämta rätt produkt från DB productId = merchantId + "-" + sku.SKU; var product = merchRepo.GetProduct(productId); if (product == null) { continue; } //Uppdatera lokala variabeln product.Status = sku.Status.ToString(); product.ExposedStatus = sku.ExposeStatus.ToString(); product.StockQuantity = sku.InStock; foreach (var channel in sku.Channels) { var channelName = _channelMappings[channel.Channel]; var productChannel = product.SalesChannels.FirstOrDefault(p => string.Equals(p.Culture, channelName, StringComparison.OrdinalIgnoreCase)); if (productChannel == null) { continue; } productChannel.Sellable = channel.Sellable; productChannel.OrdinaryPrice = channel.OrdinaryPrice; productChannel.CurrentPrice = channel.CurrentPrice; productChannel.VAT = channel.VAT; } //Skriv till ES anropa update i repository merchRepo.UpdateProduct(product); } return(true); }