public Product Post(string id, [FromBody]Product request) { if (String.IsNullOrWhiteSpace(id)) throw HttpResponseFactory.BadRequest("Product ID must be provided."); if (request == null) throw HttpResponseFactory.BadRequest("Product must be included in the body."); var product = this.configuration.Products .FirstOrDefault( p => p.ProductId.Equals(id, StringComparison.InvariantCultureIgnoreCase)); if (product == null) { product = new Product(); product.ProductId = id; this.configuration.Products.Add(product); } // Update the casing of the ProductId if it was sent if (id.Equals(request.ProductId, StringComparison.InvariantCultureIgnoreCase)) product.ProductId = request.ProductId; product.Schedule = request.Schedule; if (product.Schedule == null) product.Schedule = new Schedule(); this.configuration.SaveProduct(product); return product; }
public void SaveProduct(Product newProduct) { var products = Products; products.RemoveAll(p => p.ProductId.Equals(newProduct.ProductId, StringComparison.InvariantCultureIgnoreCase)); products.Add(newProduct); this.cache.InsertObject(PRODUCTS_KEY, products); }