public ActionResult CartSummary() { var cart = BooksCart.GetCart(this.HttpContext); ViewData["CartCount"] = cart.GetCount(); return(PartialView("CartSummary")); }
private void MigrateShoppingCart(string UserName) { // Associate shopping cart items with logged-in user var cart = BooksCart.GetCart(this.HttpContext); cart.MigrateCart(UserName); Session[BooksCart.CartSessionKey] = UserName; }
public ActionResult AddToCart(int id) { var addedBook = storeDB.Books .Single(book => book.BookID == id); var cart = BooksCart.GetCart(this.HttpContext); cart.AddToCart(addedBook); return(RedirectToAction("Index")); }
public ActionResult Index() { var cart = BooksCart.GetCart(this.HttpContext); var viewModel = new BooksCartViewModel { CartItems = cart.GetCartItems(), CartTotal = cart.GetTotal() }; return(View(viewModel)); }
public ActionResult RemoveFromCart(int id) { var cart = BooksCart.GetCart(this.HttpContext); string bookName = storeDB.Carts.Single(item => item.RecordID == id).Book.title; int itemCount = cart.RemoveFromCart(id); var results = new BooksCartRemoveViewModel { Message = Server.HtmlEncode(bookName) + " - usunięto z koszyka.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = itemCount, DeleteId = id }; return(Json(results)); }
public ActionResult AddressAndPayment(FormCollection values) { var order = new Order(); TryUpdateModel(order); try { if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { var userIdd = User.Identity.GetUserId(); if (userIdd == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } order.UserID = userIdd; order.OrderDate = DateTime.Now; order.Username = User.Identity.Name; storeDB.Orders.Add(order); storeDB.SaveChanges(); var cart = BooksCart.GetCart(this.HttpContext); cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.OrderID })); } } catch { return(View(order)); } }