public OrderMailViewModel GetOrderMail(Order order) { var model = new OrderMailViewModel(); var person = order.Person; if (person != null) { var deliveryTime = deliveryTimeProvider.GetDeliveryTime(order.DeliveryTime); model.OrderNo = order.OrderNo; model.CustomerName = String.Format("{0} {1}", person.FirstName, person.LastName); model.DeliveryDate = order.DeliveryDate.GetValueOrDefault(); model.DeliveryTimeName = deliveryTime.Name; model.OrderDate = order.OrderDate; model.CustomerMail = person.Email; } return(model); }
public IActionResult OrderMail(OrderMailViewModel orderForm) { if (ModelState.IsValid) { try { // Собираем инфу из Cart var cartInfo = string.Empty; for (var i = 0; i < Cart.Specifications.Count; i++) { // Наименование cartInfo += $@" {i+1}. {Cart.Specifications[i].Product.Name}:"; // Названия свойств и значения for (var j = 0; j < Cart.Specifications[i].SpecificationValues.Count; j++) { cartInfo += $@" {Cart.Specifications[i].SpecificationValues[j].SpecificationTitle.Name}: {Cart.Specifications[i].SpecificationValues[j].Value}"; } // Цена cartInfo += $@" Цена: {Cart.Specifications[i].Price}"; // Кол-во cartInfo += $@" Количество: {Cart.SpecificationQuantities[Cart.Specifications[i].Id]}"; // Стоимость cartInfo += $@" Сумма: {Cart.Specifications[i].Price * Cart.SpecificationQuantities[Cart.Specifications[i].Id]}"; cartInfo += "\n"; } cartInfo += $@" Всего шт.: {Cart.TotalQuantity} На сумму: {Cart.TotalPrice} "; this.Subject = "Заказ!"; this.BodyContent = $@" Заказ! ФИО: {orderForm.Name} Телефон: {orderForm.Phone} Email: {orderForm.Email} Адрес: {orderForm.Address} Тип доставки: {orderForm.DeliveryType} Примечания: {orderForm.Misc} Корзина заказа: {cartInfo}"; var mimeMessage = new MimeMessage(); mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress)); mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress)); mimeMessage.Subject = Subject; mimeMessage.Body = new TextPart("plain") { Text = BodyContent }; using (var client = new SmtpClient()) { client.Connect(SmtpServer, SmtpPortNumber, false); // Note: only needed if the SMTP server requires authentication // Error 5.5.1 Authentication client.Authenticate(UserName, Password); client.Send(mimeMessage); client.Disconnect(true); } return(this.PartialView("~/Views/Cart/_OrderForm.cshtml")); } catch (Exception ex) { throw ex; } } return(this.PartialView("~/Views/Cart/_OrderForm.cshtml")); }