예제 #1
0
        private lineItemType[] GetLineItems(List <Product> products)
        {
            lineItemType[] items = new lineItemType[products.Count];

            int count = 0;

            foreach (var value in products)
            {
                //COME BACK TO THIS AND FIX UP
                items[count] = new lineItemType
                {
                    itemId    = value.ID.ToString(),
                    name      = value.Name,
                    quantity  = _basket.GetAllItems().Count(),
                    unitPrice = (decimal)value.Price
                };
            }
            return(items);
        }
        /// <summary>
        /// sends an email to the user with information from their transaction on the order page
        /// </summary>
        /// <param name="email">identification for the user </param>
        /// <returns>thank you message and email to given email address</returns>
        public async Task <string> SendRecieptEmail(string email)
        {
            if (_shop.Basket != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<h1>Thank you for your purchase!</h1>");
                sb.AppendLine("The items you have purchased are: <ul>");
                var collection = _basket.GetAllItems();

                foreach (var value in collection)
                {
                    sb.Append($"<li>Product: {value.Product.Name} Price: {value.Product.Price}</li>");
                }
                sb.Append("</ul>");
                sb.AppendLine("<h3>Thank you for your purchase!</h3>");
                var recieptEmail = sb.ToString();

                await _emailSender.SendEmailAsync(email, "Completed Purchase", recieptEmail);

                return("Success");
            }
            return("Fail");
        }