Esempio n. 1
0
 public int AddOrder(Order order)
 {
     foreach (var orderItem in order.OrderItems)
     {
         _store.OrderItems.Add(orderItem);
     }
     _store.Orders.Add(order);
     _store.SaveChanges();
     return order.Id;
 }
Esempio n. 2
0
        public ActionResult Edit(Order model, FormCollection form)
        {
            var order = _repository.GetOrder(model.Id);

            TryUpdateModel(order, new[] { "CustomerName", "CustomerPhone", "CustomerEmail", "Completed", "Info", "Subscribed", "DeliveryCity", "DeliveryStreet", "DeliveryOffice" });
            order.DeliveryMethod = form["delivery-method"] == "delivery" ? 0 : 1;
            order.PaymentMethod = form["payment-method"] == "cache" ? 0 : 1;
            _repository.SaveOrder(order);
            return RedirectToAction("Index");
        }
Esempio n. 3
0
 public void SaveOrder(Order order)
 {
     var cache = _store.Orders.Single(c => c.Id == order.Id);
     cache.Completed = order.Completed;
     cache.CustomerEmail = order.CustomerEmail;
     cache.CustomerName = order.CustomerName;
     cache.CustomerPhone = order.CustomerPhone;
     cache.DeliveryAddress = order.DeliveryAddress;
     cache.DeliveryCity = order.DeliveryCity;
     cache.DeliveryMethod = order.DeliveryMethod;
     cache.DeliveryOffice = order.DeliveryOffice;
     cache.DeliveryStreet = order.DeliveryStreet;
     cache.Info = order.Info;
     cache.PaymentMethod = order.PaymentMethod;
     cache.Subscribed = order.Subscribed;
     _store.SaveChanges();
 }
Esempio n. 4
0
        public static void Notify(Order order, int number)
        {
            string[] mailTo = ConfigurationManager.AppSettings["mailTo"].Split(new[] { " ", ";", "," }, StringSplitOptions.RemoveEmptyEntries);
            SmtpClient client = new SmtpClient();
            MailMessage message = new MailMessage();
            foreach (var mailAddress in mailTo)
            {
                message.To.Add(mailAddress);
            }
            if (order.Subscribed && !string.IsNullOrEmpty(order.CustomerEmail))
            {
                message.To.Add(order.CustomerEmail);
            }
            message.Subject = "active-land заказ";
            message.Body =
                string.Format(
                    "<div>Номер заказа: {8}</div><div>Имя: {0}</div><div>Телефон: {1}</div><div>Email: {2}</div><div>Город: {3}</div><div>Улица: {4}</div><div>Дом: {5}</div><div>Способ оплаты: {6}</div><div>Способ доставки: {7}</div>",
                    order.CustomerName,
                    order.CustomerPhone,
                    order.CustomerEmail,
                    order.DeliveryCity,
                    order.DeliveryStreet,
                    order.DeliveryOffice,
                    order.PaymentMethod == 0 ? "Наличными" : "Картой",
                    order.DeliveryMethod == 0 ? "Доставка" : "Самовывоз",
                    number);

            foreach (var orderItem in order.OrderItems)
            {
                message.Body += string.Format(
                    "<div>Название: {0}</div><div>Артикул: {1}</div><div>Цвет: {2}</div><div>Размер: {3}</div>",
                    orderItem.ProductTitle,
                    orderItem.ProductStockNumber,
                    orderItem.ProductColor,
                    orderItem.ProductSize);
            }

            message.IsBodyHtml = true;
//#if !DEBUG
            client.Send(message);
//#endif
            message.Dispose();
        }
Esempio n. 5
0
        public ActionResult CheckOut(FormCollection form)
        {

            var order = new Order
                {
                    CustomerName = form["customerName"],
                    CustomerPhone = form["mobilePhone"],
                    Date = DateTime.Now,
                    CustomerEmail = form["email"],
                    Subscribed = form["subscribe-radio"] == "ok",
                    Completed = false,
                    // 0 - Доставка 
                    // 1 - Самовывоз
                    DeliveryMethod = form["delivery-method"] == "delivery" ? 0 : 1,
                    DeliveryCity = form["city"],
                    DeliveryStreet = form["street"],
                    DeliveryOffice = form["office"],
                    // 0 - Наличными
                    // 1 - Оплата карточкой
                    PaymentMethod = form["payment-method"] == "cache" ? 0 : 1,
                };

            foreach (var orderItem in WebSession.OrderItems.Select(o => o.Value))
            {
                foreach (var productStock in orderItem.ProductStocks.Where(ps=>ps.StockNumber==form["stock"]))
                {
                    orderItem.ProductStockNumber = productStock.StockNumber;
                    orderItem.ProductColor = productStock.Color;
                    orderItem.ProductSize = productStock.Size;
                }

                order.OrderItems.Add(orderItem);
            }

            if (order.OrderItems.Any())
            {
                WebSession.Order = order;
                
                //WebSession.OrderItems.Clear();
            }

            return RedirectToAction("CheckOutConfirm");
        }