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); }
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); }
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); }
public async Task <int> CartCount() { var cart = await ShoppingCartService.GetCart(); return(await cart.GetCount()); }