Exemplo n.º 1
0
        public EmailTemplate GetSalesTemplate(Order order)
        {
            string body = salesTemplate.Body.Replace("@userName",
                                                     string.IsNullOrEmpty(order.User) ? string.Empty : order.User.Trim());
            body = body.Replace("@userEmail", string.IsNullOrEmpty(order.Email) ? string.Empty : order.Email.Trim());
            body = body.Replace("@userCity", string.IsNullOrEmpty(order.City) ? string.Empty : order.City.Trim());
            body = body.Replace("@userAddress",
                                string.IsNullOrEmpty(order.Address) ? string.Empty : order.Address.Trim());
            CultureInfo culture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("uk-UA");
            body = body.Replace("@orderCreationDate", order.CreationDate.ToString("G"));
            Thread.CurrentThread.CurrentCulture = culture;
            body = body.Replace("@userPhone", string.IsNullOrEmpty(order.Phone) ? string.Empty : order.Phone.Trim());
            body = body.Replace("@userComment",
                                string.IsNullOrEmpty(order.Comment) ? string.Empty : order.Comment.Trim());

            IEnumerable<int> ids = order.Items.Select(obj => obj.ProductId);
            IEnumerable<Product> products = productRepository.GetByIds(ids);
            using (var stringWriter = new StringWriter())
            using (var writer = new HtmlTextWriter(stringWriter))
            {
                foreach (OrderItem item in order.Items)
                {
                    Product product = products.Single(obj => obj.Id == item.ProductId);
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(product.DisplayName);
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(item.Quantity);
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write("{0} грн.", item.UnitPrice);
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write("{0} грн.", item.TotalItemPrice);
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                }

                body = body.Replace("@orderItemsContent", stringWriter.ToString());
            }

            body = body.Replace("@totalSum", string.Format("{0:0.##}", order.Total));
            return new EmailTemplate(body, salesTemplate.Subject);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 public OrderDetailViewModel(Order order, IEnumerable<Product> products)
 {
     this.Order = order;
     this.Products = products;
 }
Exemplo n.º 4
0
        public ActionResult Edit(Order order)
        {
            if (ModelState.IsValid)
            {
                orderRepository.Update(order);
                using (UnitOfWork)
                {
                    UnitOfWork.Commit();
                }
                return RedirectToAction("list");
            }

            return View(order);
        }