예제 #1
0
 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;
 }
예제 #2
0
        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;
        }
예제 #3
0
 public ActionResult Create(Product postData)
 {
     var repo = new ProductRepository();
     repo.AddProduct(postData);
     return Json(new { id = postData.Id });
 }