Beispiel #1
0
        public ActionResult Save(Product products)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateProduct"));
            }

            try
            {
                if (products == null)
                {
                    return(View("CreateProduct"));
                }


                if (products.Id == 0)
                {
                    _productApplication.Register(products);
                }
                else
                {
                    _productApplication.Update(products);
                }


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("CreateProduct"));
            }
        }
Beispiel #2
0
        public void Product_Update_Null()
        {
            // Arrange
            var notificator        = new Mock <INotificator>();
            var productRepository  = new Mock <IProductRepository>();
            var productApplication = new ProductApplication(notificator.Object, productRepository.Object);
            var productFake1       = NewProduct();
            var productFake2       = productFake1;

            productFake2.Name = "Shampoo B";

            // Act
            var product = productApplication.Update(productFake2);

            // Assert
            Assert.Null(product);
        }
        public ActionResult Edit(Guid id, ProductViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                this.AddToastMessage("", "Error while editing Product.", ToastType.Error);
                ViewBag.Categories = new SelectList(_categoryApplication.List(), "Id", "Name");
                return(View("Edit", vm));
            }

            var result = _productApplication.Update(vm, id);


            if (result)
            {
                this.AddToastMessage("", "Product edited with success.", ToastType.Success);
                return(RedirectToAction("Index"));
            }
            else
            {
                this.AddToastMessage("", "Error while editing Product.", ToastType.Error);
                ViewBag.Categories = new SelectList(_categoryApplication.List(), "Id", "Name");
                return(View("Edit", vm));
            }
        }