public void SendNewOrderMail(int orderId) { HostingEnvironmentPolyfills.QueueBackgroundWorkItemPf(async ct => { NewOrderEmailModel emailModel = new NewOrderEmailModel(); OrdersProvider ordersProvider = new OrdersProvider(); Order order = await ordersProvider.GetFullOrderData(orderId); string toEmailAddress; using (ApplicationDbContext appContext = new ApplicationDbContext()) { string userId = order.UserId.ToString(); Address userAddress = await appContext.AddressInfos.FirstOrDefaultAsync(a => a.UserId == userId); emailModel.Country = userAddress.Country; emailModel.City = userAddress.City; emailModel.District = userAddress.District; emailModel.PostCode = userAddress.PostCode; emailModel.Commune = userAddress.Commune; emailModel.AddresDetails = userAddress.AddresDetails; emailModel.FullName = string.Format("{0} {1} {2}", userAddress.FirstName, userAddress.MiddleName, userAddress.LastName); emailModel.Phone = userAddress.Phone; toEmailAddress = userAddress.Email; } emailModel.BaseUrl = ConfigurationManager.AppSettings["Site.BaseUrl"]; emailModel.ContactUsFormUrl = string.Concat(emailModel.BaseUrl, ConfigurationManager.AppSettings["Site.ContactUsFormUrl"].TrimStart('/')); emailModel.OrdersPageUrl = string.Concat(emailModel.BaseUrl, ConfigurationManager.AppSettings["Site.OrdersPageUrl"].TrimStart('/')); emailModel.OrderNumber = order.Id; emailModel.CommissionPercents = order.HasCommission ? order.CommissionPercents : 0; emailModel.DeliveryMerchant = order.DeliveryMerchant; emailModel.ShippingPrice = order.ShippingPrice.ToString("N2") + "лв"; emailModel.TotalPrice = order.TotalPrice.ToString("N2") + "лв"; emailModel.Items = order.OrderDetails.Select(od => new Item() { Title = od.Article.Title, Quantity = od.Quantity, Price = od.ItemPrice.ToString("N2") + "лв" }).ToList(); string emailContent = templateEngine.RenderTemplate("NewOrder", emailModel); await this.mailSender.SendEmail(toEmailAddress, string.Format("{0}: Поръчка #{1}", emailModel.BaseUrl, emailModel.OrderNumber), emailContent); }); }