示例#1
0
        public async Task <ShoppingCartRemoveViewModel> RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = await ShoppingCartService.GetCart();

            // Get the name of the item to display confirmation

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

            // Remove from cart
            int itemCount = await cart.RemoveFromCartItem(id);

            // Display the confirmation message
            var results = new ShoppingCartRemoveViewModel
            {
                Message = "One (1) " + HttpUtility.HtmlEncode(itemName) +
                          " has been removed from your shopping cart.",
                CartTotal = await cart.GetTotal(),
                CartCount = await cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            return(results);
        }
示例#2
0
        public async Task <ShoppingCartViewModel> shoppingCart()
        {
            var cart = await ShoppingCartService.GetCart();

            //Set up our ViewModel
            var viewModel = new ShoppingCartViewModel
            {
                CartItems = await cart.GetCartItems()
            };

            //Return the view
            return(viewModel);
        }
示例#3
0
        public async Task <ShoppingCartRemoveViewModel> AddToCart(int id)
        {
            // Retrieve the item from the database
            var addedItem = await storeDB.Items
                            .SingleAsync(item => item.Id == id);

            // Add it to the shopping cart
            var cart = await ShoppingCartService.GetCart();

            int count = await cart.AddToCart(addedItem);

            // Display the confirmation message
            var results = new ShoppingCartRemoveViewModel
            {
                Message = HttpUtility.HtmlEncode(addedItem.Name) +
                          " has been added to your shopping cart.",
                CartTotal = await cart.GetTotal(),
                CartCount = await cart.GetCount(),
                ItemCount = count,
                DeleteId  = id
            };

            return(results);
        }
示例#4
0
        public async Task <int> CartCount()
        {
            var cart = await ShoppingCartService.GetCart();

            return(await cart.GetCount());
        }