public ActionResult RemoveFromCart(string id) { ShoppingCart cart = new ShoppingCart(this.HttpContext); // remove from cart cart.RemoveFromCart(id); return RedirectToAction("Index"); }
// GET: /Store/AddToCart/5 public ActionResult AddToCart(string id) { // find the book in db and get book , id must have value var bookInDB = storeDB.Books.Single(book => book.BookIsbn == id); // create cart object with this session ShoppingCart cart = new ShoppingCart(this.HttpContext); // Add it to the shopping cart cart.AddToCart(bookInDB); return RedirectToAction("Index"); }
// GET: ShoppingCart public ActionResult Index() { ShoppingCart cart = new ShoppingCart(this.HttpContext); // Set up our ViewModel var viewModel = new ShoppingCartViewModel { CartItems = cart.GetCartItems(), CartTotal = cart.GetTotal() }; return View(viewModel); }
public ActionResult AddressAndPayment(FormCollection form) { Order order = new Order(); TryUpdateModel(order); try { order.OrderDate = DateTime.Now; // Save Order storeDB.Orders.Add(order); storeDB.SaveChanges(); // Process order ShoppingCart cart = new ShoppingCart(this.HttpContext); cart.CreateOrder(order); return RedirectToAction("Complete", new { id = order.OrderId }); } catch { return View(order); } }