public async Task <IActionResult> Index() { var userid = _userManager.GetUserId(User); var baskets = await _basket.GetBasketItems(userid); List <Product> products = new List <Product>(); foreach (var item in baskets) { var product = await _product.GetProduct(item.ProductID); products.Add(product); } var combo = baskets.Zip(products, (x, y) => new { BasketItem = x, Product = y }); List <BasketViewModel> BasketList = new List <BasketViewModel>(); foreach (var item in combo) { BasketViewModel BasketVM = new BasketViewModel(); BasketVM.Sku = item.Product.Sku; BasketVM.Name = item.Product.Name; BasketVM.Price = item.Product.Price; BasketVM.Description = item.Product.Description; BasketVM.Image = item.Product.Image; BasketVM.ProductID = item.Product.ProductID; BasketVM.Quantity = item.BasketItem.Quantity; BasketVM.ID = item.BasketItem.ID; BasketList.Add(BasketVM); } return(View(BasketList)); //return View(await _basket.GetBasketItems()); }
public async Task <IActionResult> Receipt(string email) { var userid = _userManager.GetUserId(User); var baskets = await _basket.GetBasketItems(userid); List <Product> products = new List <Product>(); foreach (var item in baskets) { var product = await _product.GetProduct(item.ProductID); products.Add(product); } var combo = baskets.Zip(products, (x, y) => new { BasketItem = x, Product = y }); List <BasketViewModel> BasketList = new List <BasketViewModel>(); foreach (var item in combo) { BasketViewModel BasketVM = new BasketViewModel(); BasketVM.Sku = item.Product.Sku; BasketVM.Name = item.Product.Name; BasketVM.Price = item.Product.Price; BasketVM.Description = item.Product.Description; BasketVM.Image = item.Product.Image; BasketVM.ProductID = item.Product.ProductID; BasketVM.Quantity = item.BasketItem.Quantity; BasketVM.ID = item.BasketItem.ID; BasketVM.Purchased = item.BasketItem.Purchased; BasketVM.PurchaseDate = item.BasketItem.PurchaseDate; BasketList.Add(BasketVM); } string subject = "Order Confirmation"; string msg = "<table><th>Product</th><th>Quantity</th><th>Price</th>"; decimal total = 0m; foreach (var item in BasketList) { var product = await _product.GetProduct(item.ProductID); total += (product.Price * item.Quantity); msg += $"<tr><td>{product.Name}</td><td>{item.Quantity}</td><td>${product.Price}</td></tr>"; } msg += $"<tr><td>Total:</td><td> </td><td>${total}</td></tr>"; await _email.SendEmailAsync(email, subject, msg); await _basket.HandleBasketItems(BasketList); return(View(BasketList)); }