Пример #1
0
        public bool Add(Order order)
        {
            foreach (CartItem item in Cart.Items)
            {
                order.Items.Add(new OrderItem
                    {
                        ProductId = item.Product.Id,
                        Quantity = item.Quantity,
                        UnitPrice = item.Product.CalculatedPrice.PriceFinalUah
                    });
            }

            order.Status = Status.Pending;
            order.CreationDate = DateTime.Now.ToUkrainianTimeZone();
            orderRepository.Add(order);
            try
            {
                var templatesProvider = new EmailTemplatesProvider(productRepository);
                UnitOfWork.Commit();
                Task.Factory.StartNew(() =>
                    {
                        var message = new NotificationMessage
                            {
                                EmailTemplate = templatesProvider.GetCustomerOrderTemplate(order.User, order.Total),
                                To = new[] {order.Email}
                            };
                        NotificationManager.Current.Notify(message);
                        message = new NotificationMessage
                            {
                                EmailTemplate = templatesProvider.GetSalesTemplate(order),
                                To = new[] {Constants.SalesEmail}
                            };
                        NotificationManager.Current.Notify(message);
                    }).ContinueWith(obj => UnitOfWork.Dispose());
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            RemoveCart();
            return true;
        }
Пример #2
0
        public void SendEmail(NotificationMessage message)
        {
            var basicAuthenticationInfo = new NetworkCredential(Settings.SmtpUserAccount, Settings.SmtpUserPassword);
            var smtp = new SmtpClient(Settings.SmtpHost)
            {
                UseDefaultCredentials = false,
                Credentials = basicAuthenticationInfo
            };

            var mailMessage = new MailMessage();

            foreach (var toEmail in message.To)
            {
                mailMessage.To.Add(toEmail);
            }
            foreach (var replyToEmail in Settings.ReplyTo)
            {
                mailMessage.ReplyToList.Add(replyToEmail);
            }
            foreach (var ccEmail in Settings.CC)
            {
                mailMessage.CC.Add(ccEmail);
            }
            foreach (var bccEmail in Settings.BCC)
            {
                mailMessage.Bcc.Add(bccEmail);
            }

            mailMessage.Subject = message.EmailTemplate.Subject;
            mailMessage.SubjectEncoding = Encoding.UTF8;
            mailMessage.From = new MailAddress(Settings.From);

            mailMessage.BodyEncoding = Encoding.UTF8;
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = message.EmailTemplate.Body;
            smtp.SendCompleted += this.SendCompleted;
            smtp.SendAsync(mailMessage, null);
        }