public void CreateOption(Guid productId, ProductOption productOption) { if (ProductExists(productId)) { productOption.ProductId = productId; productOption.CreatedDate = DateTime.Now; productOption.ModifiedDate = DateTime.Now; Context.ProductOptions.Add(productOption); try { Context.SaveChanges(); } catch (DbUpdateException) { var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable) { Content = new StringContent("ProductOptions Details not created"), ReasonPhrase = "ProductOptions Details not created" }; throw new HttpResponseException(response); } } else { var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("Product ID is not found Id= {0}", productId)), ReasonPhrase = " Product ID is not found" }; throw new HttpResponseException(response); } }
public void UpdateProduct(Guid productid, Product product) { if (!ProductExists(productid)) { var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No Product Found with Id= {0}", productid)), ReasonPhrase = "No Products Found" }; throw new HttpResponseException(response); } else { Product res = Context.Products.Single(p => p.Id.Equals(productid)); res.Name = product.Name; res.Description = product.Description; res.Price = product.Price; res.DeliveryPrice = product.DeliveryPrice; res.ModifiedDate = DateTime.Now; try { Context.SaveChanges(); } catch (Exception ex) { var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable) { Content = new StringContent("Product Details not updated"), ReasonPhrase = "Product Details not updated" }; throw new HttpResponseException(response); } } }