Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
 public ActionResult Create(Product postData)
 {
     var repo = new ProductRepository();
     repo.AddProduct(postData);
     return Json(new { id = postData.Id });
 }