Пример #1
0
        /// <summary>
        /// Deleting the cart items as soon as user's done with their purchase
        /// </summary>
        public async Task ReceiptDelete()
        {
            var userName = User.Identity.Name;
            var userId   = await _CartManager.GetCartById(userName);

            List <CartItems> CartItems = await _CartManager.GetProductByCartID(userId.ID);

            TempData["ListOfProduct"] = CartItems;
            foreach (var item in CartItems)
            {
                decimal TempTotal = item.Product.Price * item.Quantity;
                TotalPrice += TempTotal;
                await _CartItemsManager.DeleteCartItems(item.ID);
            }

            /// Creating a letter to send it to user when they purchase
            StringBuilder sb = new StringBuilder();

            string imageUrl = "https://i.imgur.com/rocGIxN.png";

            sb.AppendLine($"<div style='text-align:center'>");
            sb.AppendLine($"<img src='{imageUrl}' alt='Logo' style='margin-bottom:50px' />");
            sb.AppendLine("<h3 style='margin-bottom:15px'>Receipt</h3>");


            sb.AppendLine($"<div style='text-align:center; margin-top:80px'>");
            foreach (var item in CartItems)
            {
                sb.AppendLine($"<h5>{item.Product.Name} </h5>");
                sb.AppendLine($"<p>Price: {item.Product.Price} </p>");
                sb.AppendLine($"<p>Quantity: {item.Quantity} </p>");
                sb.AppendLine("<hr />");
            }
            sb.AppendLine($"<p>Total: {TotalPrice} </p>");
            sb.AppendLine($"<p>Thank you for the purchase!</p>");
            sb.AppendLine($"<p>We will start on it right away! </p>");
            sb.AppendLine("</div>");
            sb.AppendLine("</div>");

            /// sending the receipt to the shopper
            await _Email.SendEmailAsync(userName, "Thank you for the order", sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Rerouting to the cart after its been deleted
        /// </summary>
        /// <param name="ID">ID of the item to be deleted</param>
        /// <returns>Cart page</returns>
        public async Task <IActionResult> OnGet(int ID)
        {
            await _cartItemsManager.DeleteCartItems(ID);

            return(RedirectToPage("/Cart/Index"));
        }