public void ProcessOrder(Entities.Basket basket, Entities.DeliveryDetails delivery) { using (var SmtpClient = new SmtpClient()) { SmtpClient.EnableSsl = emailSettings.UseSsl; SmtpClient.Host = emailSettings.ServerName; SmtpClient.Port = emailSettings.ServerPort; SmtpClient.UseDefaultCredentials = false; SmtpClient.Credentials = new NetworkCredential(emailSettings.UserName, emailSettings.Password); if (emailSettings.WriteAsFile) { SmtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; SmtpClient.PickupDirectoryLocation = emailSettings.FileLocation; SmtpClient.EnableSsl = false; } StringBuilder body = new StringBuilder() .AppendLine("Новый заказ обработан") .AppendLine("-----") .AppendLine("Товары:"); foreach (var item in basket.GetGoods) { var subTotal = item.Book.Price * item.Quantity; body.AppendFormat("{0} x {1} (итого: {2} руб.)\n", item.Quantity, item.Book.Name, subTotal); } body.AppendFormat("\n\nОбщая стоимость: {0} руб.", basket.TotalSum()) .AppendLine("\n-----") .AppendLine("Параметры заказа:") .AppendLine(delivery.FIO) .AppendLine(delivery.Phone) .AppendLine(delivery.Email) .AppendLine(delivery.TypeDelivery) .AppendLine(delivery.TypePaySystem) .AppendLine("-----") .AppendLine("Дополнение к заказу:") .AppendLine(delivery.Comment); //body.AppendFormat("Общая стоимость: {0}", basket.TotalSum()) // .AppendLine("-----") // .AppendLine("Доставка:") // .AppendLine(delivery.FIO) // .AppendLine(delivery.Phone) // .AppendLine(delivery.Email) // .AppendLine(delivery.Basket.GetGoods.ToString()) // .AppendLine(delivery.TypeDelivery) // .AppendLine(delivery.TypePaySystem) // .AppendLine("-----"); MailMessage mailMessage = new MailMessage( emailSettings.MailFormAddress, emailSettings.MailToAddress, "Новый заказ обработан", body.ToString() ); if (emailSettings.WriteAsFile) { mailMessage.BodyEncoding = Encoding.UTF8; } SmtpClient.Send(mailMessage); } }
public async Task <Entities.Basket> UpsertBasket(Entities.Basket shoppingCart) { await _redisCache.SetStringAsync(shoppingCart.UserName, JsonSerializer.Serialize(shoppingCart)); return(await GetBasket(shoppingCart.UserName)); }