예제 #1
0
        public bool EditProduct(string id, EditProductServiceModel model)
        {
            Product currProduct = null;

            try
            {
                currProduct = this._mapper.Map <Product>(model);
            }
            catch (Exception)
            {
                throw new ArgumentException(ExceptionMessages.InvalidProductType);
            }

            var productToUpdate = this._db.Products.FirstOrDefault(p => p.Id == id);

            if (productToUpdate == null)
            {
                throw new ArgumentException(ExceptionMessages.NoProductWithGivenId);
            }

            productToUpdate.Price       = currProduct.Price;
            productToUpdate.Name        = currProduct.Name;
            productToUpdate.ProductType = currProduct.ProductType;

            int affectedRows = this._db.SaveChanges();

            return(affectedRows > 0);
        }
예제 #2
0
        public IActionResult Edit(EditProductServiceModel model)
        {
            this._productService.EditProduct(model.Id, model);

            return(RedirectToAction("Index"));
        }