public void AddNewProduct(ProductShortInfoBean productbean) { if (productbean == null) { throw new Exception("Add New Product Error with empty product"); } if (productbean.Groupid <= 0) { throw new Exception("Add New Product Error with empty manufacture"); } if (string.IsNullOrEmpty(productbean.Name.Trim())) { throw new Exception("Add New Product Error with empty product name"); } try { Product product = new Product() { Name = productbean.Name, Price = productbean.Price, ProductGroupId = productbean.Groupid, Img = DEFAULT_AVATAR }; _productRepo.Save(product); } catch (Exception e) { throw new Exception("Add New Product Error: " + e.Message); } }
public void UpdateProduct(ProductShortInfoBean productbean) { try { Product product = _productRepo.GetProduct(productbean.Id); product.Name = productbean.Name; product.Price = productbean.Price; _productRepo.Update(product); } catch (Exception e) { throw new Exception("Update Product Error : " + e.Message); } }
public ActionResult Put([FromBody] ProductShortInfoBean productBean) { return(new ActionResult(() => { _productService.UpdateProduct(productBean); return null; })); }
public ActionResult Post([FromBody] ProductShortInfoBean productbean) { return(new ActionResult(() => { _productService.AddNewProduct(productbean); return null; })); }