public ActionResult AddProduct(AddProductViewModel 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.AddProduct(product, new Quantity(model.Quantity)); transaction.Commit(); } return RedirectToAction("Index"); }
public void AddProductToCart() { 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 AddProductViewModel() { CustomerId = ((List<Customer>)customersViewResult.Model)[0].Id, ProductId = ((List<Product>)productsViewResult.Model)[0].Id, Quantity = 1 }; var result = cartController.AddProduct(model) as RedirectToRouteResult; }