public async Task <IActionResult> Details(int?id) { UserViewModel uvm = new UserViewModel(); if (id.HasValue) { uvm.Product = await _context.GetProductByID(id.Value); if (uvm.Product != null) { return(View(uvm)); } return(RedirectToAction("Index", "Admin")); } return(RedirectToAction("Index", "Admin")); }
/// <summary> /// Action that gives the user a view of their cart. It gives them the total price /// as well as an option to checkout and complete their order /// </summary> /// <returns>View with a UserViewModel</returns> public async Task <IActionResult> Index() { decimal total = 0; var userID = _userManager.GetUserId(User); if (!String.IsNullOrEmpty(userID)) { var cart = await _cart.GetCart(userID); cart.CartItems = await _cart.GetCartItems(cart.ID); foreach (CartItem item in cart.CartItems) { item.Product = await _context.GetProductByID(item.ProductID); total = total + (item.Product.Price * item.Quantity); } UserViewModel uvm = new UserViewModel { Cart = cart, Total = total }; return(View(uvm)); } return(RedirectToAction("Index", "Shop")); }