Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 public ActionResult Put([FromBody] ProductShortInfoBean productBean)
 {
     return(new ActionResult(() => { _productService.UpdateProduct(productBean); return null; }));
 }
Ejemplo n.º 4
0
 public ActionResult Post([FromBody] ProductShortInfoBean productbean)
 {
     return(new ActionResult(() => { _productService.AddNewProduct(productbean); return null; }));
 }