public async Task <IActionResult> Review() { //get user ID string userEmail = User.Identity.Name; var user = await _userManager.FindByEmailAsync(userEmail); string userID = user.Id; //move all shopping items in cart to order items //find their carts Cart cartObj = await _cart.GetCart(userID); //get all the items in the cart IEnumerable <ShoppingCartItem> cartitems = await _shoppingCartItem.GetAllShoppingCartItems(cartObj.ID); if (cartitems.Count() <= 0) { return(RedirectToAction("Index", "Product")); } else { decimal totalprice = 0m; //convert it to orderitem foreach (var item in cartitems) { totalprice += (item.ProdQty * item.Product.Price); } Order ord = new Order(); ord.UserID = userID; ord.Totalprice = totalprice; await _order.CreateOrder(ord); foreach (var item in cartitems) { OrderedItems tempOrdItem = new OrderedItems(); tempOrdItem.OrderID = ord.ID; tempOrdItem.ProductID = item.ProductID; tempOrdItem.ProdQty = item.ProdQty; await _ordereditems.CreateOrderedItem(tempOrdItem); } List <OrderedItems> ordedItems = await _ordereditems.GetAllOrderedItems(ord.ID); string emailMessage = ReceiptEmailBuilder(ord, ordedItems).ToString(); await _emailSender.SendEmailAsync(userEmail, "Receipt for Mystical Creatures", emailMessage); return(View(await _ordereditems.GetAllOrderedItems(ord.ID))); } }
/// <summary> /// invoke the viewcomponents action here, using the useremail to find the user and find user's cart and get all the items in the cart,show them on the page /// </summary> /// <returns></returns> public async Task <IViewComponentResult> InvokeAsync() { if (User.Identity.Name != null) { string userEmail = User.Identity.Name; var user = await _userManager.FindByEmailAsync(userEmail); string userID = user.Id; var cart = _context.Carts.FirstOrDefault(i => i.UserID == userID); var pro = await _shoppingCartItem.GetAllShoppingCartItems(cart.ID); return(View(pro)); } else { return(View()); } }
/// <summary> /// default page for shopping cart, shows all items to page /// </summary> /// <returns>page to see all items</returns> public async Task <IActionResult> Index() { //find userID if (User.Identity.Name != null) { string userEmail = User.Identity.Name; var user = await _userManager.FindByEmailAsync(userEmail); string userID = user.Id; //so can find their carts Cart cartObj = await _cart.GetCart(userID); return(View(await _shoppingCartItem.GetAllShoppingCartItems(cartObj.ID))); } else //user not in DB { return(RedirectToAction("Register", "Account")); } }