Ejemplo n.º 1
0
        public ViewResult Edit(int productId)
        {
            Product product = _productsRepository.GetProductByProductId(productId);

            var productEditModel = new ProductEditModel {ProductId = product.ProductId};

            return View("Edit", productEditModel);
        }
        protected override void Arrange()
        {
            _model = new ProductEditModel
            {
                ProductName = "",
                UnitPrice = 0M,
                UnitsInStock = -1,
                CategoryId = 0,
                SupplierId = 0
            };

            _validator = new ProductEditModelValidator();
        }
Ejemplo n.º 3
0
        public ActionResult Edit(ProductEditModel productEditModel)
        {
/*            try
            {
                if (!ModelState.IsValid) return View();
                
                _productsRepository.AddProduct(productEditModel);
                
                return RedirectToAction("Index");
                
            }
            catch (Exception)
            {
                return View();
            }*/

            try
            {
                if (!ModelState.IsValid) return View();

                var product = _productsRepository.GetProductByProductId(productEditModel.ProductId);
                
                product.UnitPrice = productEditModel.UnitPrice;
                product.UnitsInStock = productEditModel.UnitsInStock;
                product.CategoryID = productEditModel.CategoryId;
                product.SupplierID = productEditModel.SupplierId;
                product.ProductName = productEditModel.ProductName;

                _productsRepository.InsertOrUpdate(product);

                _productsRepository.Save();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View("Edit");
            }


        }
 protected override void Arrange()
 {
     _productEditModel = new ProductEditModel();
    
     MockContext.Setup(x => x.Products.Add(It.IsAny<Product>())).Throws(new Exception());
 }