Exemplo n.º 1
0
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the item to display confirmation

            // Get the name of the album to display confirmation
            string itemName = storeDB.OF_Products
                              .Single(item => item.Id == id).Name;

            // Remove from cart
            int itemQty = cart.RemoveFromCart(id);

            // Send response for updated cart data
            var results = new ShoppingCartResponseViewModel
            {
                ItemName           = itemName,
                CartTotal          = cart.GetTotal(),
                CartTotalFormatted = string.Format("{0:C}", cart.GetTotal()),
                CartCount          = cart.GetCount(),
                ItemQty            = itemQty,
                DeleteId           = id
            };

            return(Json(results));
        }
Exemplo n.º 2
0
        public ActionResult AddToCart(int id)
        {
            // Retrieve the item from the database
            var addedItem = storeDB.OF_Products
                            .Single(item => item.Id == id);

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            cart.AddToCart(addedItem);

            // Send response for updated cart data
            var results = new ShoppingCartResponseViewModel
            {
                CartCount = cart.GetCount()
            };

            return(Json(results));
        }
Exemplo n.º 3
0
        public ActionResult UpdateQtyFromCart(int id, int newQty)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the item to display confirmation

            // Remove from cart
            int itemQty = cart.UpdateQtyFromCart(id, newQty);

            // Send response for updated cart data
            var results = new ShoppingCartResponseViewModel
            {
                CartTotal          = cart.GetTotal(),
                CartTotalFormatted = string.Format("{0:C}", cart.GetTotal()),
                ItemQty            = itemQty
            };

            return(Json(results));
        }