Ejemplo n.º 1
0
        public void RemoveProductFromCart()
        {
            var customerController = _container.Resolve<CustomerController>();
            var productController = _container.Resolve<ProductController>();
            var cartController = _container.Resolve<CartController>();

            var customersViewResult = customerController.Index() as ViewResult;
            var productsViewResult = productController.Index() as ViewResult;

            var model = new RemoveProductViewModel()
            {
                CustomerId = ((List<Customer>)customersViewResult.Model)[0].Id,
                ProductId = ((List<Product>)productsViewResult.Model)[0].Id
            };

            var result = cartController.RemoveProduct(model) as RedirectToRouteResult;
        }
Ejemplo n.º 2
0
        public ActionResult RemoveProduct(RemoveProductViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            using (ITransaction transaction = _session.BeginTransaction())
            {
                var cart = _cartRepository.GetCartByCustomerId(model.CustomerId);
                var product = _productRepository.GetProduct(model.ProductId);

                cart.RemoveProduct(product);

                transaction.Commit();
            }

            return RedirectToAction("Index");
        }