コード例 #1
0
        public ActionResult CartSummary()
        {
            var cart = BooksCart.GetCart(this.HttpContext);

            ViewData["CartCount"] = cart.GetCount();
            return(PartialView("CartSummary"));
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        public ActionResult Index()
        {
            var cart = BooksCart.GetCart(this.HttpContext);

            var viewModel = new BooksCartViewModel
            {
                CartItems = cart.GetCartItems(),
                CartTotal = cart.GetTotal()
            };

            return(View(viewModel));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
            }
        }