public bool UpdateProduct(Product product) { var currentProduct = Products.Where(x => x.Id == product.Id).FirstOrDefault(); if (currentProduct == null) throw new Exception("product does not exists!!"); currentProduct.Description = product.Description; currentProduct.Price = product.Price; return true; }
public bool AddProduct(Product product) { if (Products.Any(x => x.Id == product.Id)) throw new Exception("Id already exists"); if (Products.Any(x => x.Name.ToLower() == product.Name.ToLower())) throw new Exception("product with this name already exists"); Products.Add(product); return true; }
public ActionResult Create(Product postData) { var repo = new ProductRepository(); repo.AddProduct(postData); return Json(new { id = postData.Id }); }