Esempio n. 1
0
        public ActionResult Update(int orderId, int status)
        {
            Order order = daoTemplate.FindByID <Order>(orderId);

            if (status == (int)OrderStatus.Revoked)
            {
                return(Revert(orderId));
            }
            bool statusChanged = ((OrderStatus)status) != order.Status;

            order.Status = (OrderStatus)status;
            if (statusChanged)
            {
                if (order.Status == OrderStatus.Sent)
                {
                    var message = MailService.RenderViewToString("~/Views/MailTemplates/OrderSent.aspx", order, ControllerContext);
                    mailService.SendCcAdmins("Заказ отправлен - Elfam.ru", message, order.User.Email);
                }
                else if (order.Status == OrderStatus.WaitPickup)
                {
                    var message = MailService.RenderViewToString("~/Views/MailTemplates/OrderWaitPickup.aspx", order, ControllerContext);
                    mailService.SendCcAdmins("Заказ готов к самовывозу - Elfam.ru", message, order.User.Email);
                }
            }

            orderService.UpdateUserDicount(order.User, this.ControllerContext);
            daoTemplate.Save(order);
            return(RedirectToAction("Details", new { Id = order.Uid }));
        }
Esempio n. 2
0
        public void AddOrders()
        {
            return;

            ISession        session  = GetConfiguration().BuildSessionFactory().OpenSession();
            IList <User>    users    = session.CreateCriteria(typeof(User)).List <User>();
            IList <Product> products = session.CreateCriteria(typeof(Product)).List <Product>();
            Random          r        = new Random();

            foreach (User user in users)
            {
                if (user.Email.Contains("11"))
                {
                    continue;
                }
                if (user.Email.Contains("22"))
                {
                    continue;
                }
                if (user.Email.Contains("44"))
                {
                    continue;
                }
                if (user.Email.Contains("55"))
                {
                    continue;
                }
                if (user.Email.Contains("66"))
                {
                    continue;
                }
                if (user.Email.Contains("88"))
                {
                    continue;
                }

                int n = r.Next(2, 20);
                for (int i = 0; i < n; i++)
                {
                    Order order = new Order();
                    order.User            = user;
                    order.DeliverType     = (DeliverType)r.Next(3);
                    order.PaymentType     = (PaymentType)r.Next(2);
                    order.ShippingDetails = user.Contact;

                    order.Date = new DateTime(2005 + r.Next(5), r.Next(1, 12), r.Next(1, 28), r.Next(0, 23), r.Next(0, 59), r.Next(0, 59));
                    int p = r.Next(1, 7);
                    for (int j = 0; j < p; j++)
                    {
                        order.AddOrderLine(products[r.Next(products.Count)], r.Next(1, 10));
                    }
                    session.Save(order);
                    order.Uid = session.Get <UniqueId>(order.Id).Uid;
                    session.Save(order);
                }
            }
            session.Flush();
        }
Esempio n. 3
0
        public AddOrderResult AddOrder(Cart cart, User user, OrderShippingInfo orderInfo)
        {
            if (cart == null)
                throw new ArgumentException("cart is null");
            if (cart.Items == null)
                throw new ArgumentException("cart items is null");
            if (user == null)
                throw new ArgumentException("user is null");
            if (orderInfo == null)
                throw new ArgumentException("orderInfo is null");

            // construct order
            var orderLines = new List<OrderLine>();
            var orderOutcomes = new List<Outcome>();
            foreach (CartItem item in cart.Items)
            {
                IList<Income> incomes = FindOldestIncomesForProduct(item.Product, item.Quantity);
                int quantity = item.Quantity;
                var outcomes = new List<Outcome>();
                foreach (Income income in incomes)
                {
                    int n = Math.Min(quantity, income.QuantityCurrent);
                    income.QuantityCurrent -= n;
                    _daoTemplate.Save(income);
                    Outcome outcome = new Outcome(item.Product.Price, n, income, user.Discount + cart.CurrentDiscount());
                    quantity -= n;
                    outcomes.Add(outcome);
                }
                orderOutcomes.AddRange(outcomes);
                orderLines.Add(new OrderLine(item.Product, item.Quantity, outcomes));
            }
            Order order = new Order(orderOutcomes, orderLines);
            order.Comment = orderInfo.Comment ?? "";
            DeliverPrices prices = _daoTemplate.FindAll<DeliverPrices>()[0];
            if (orderInfo.PaymentType == PaymentType.OnPost)
            {
                order.DeliverPrice = prices.PostWhenReceived(cart.SummDiscount());
            }
            else
            {
                order.DeliverPrice = GetPrice(orderInfo.DeliverType);
            }
            order.CopyFrom(orderInfo);
            order.User = user;
            order.Discount = user.Discount + cart.CurrentDiscount();
            _daoTemplate.Save(order);
            order.Uid = _daoTemplate.FindByID<UniqueId>(order.Id).Uid;
            _daoTemplate.Save(order);

            return new AddOrderResult(){Order = order};
        }
Esempio n. 4
0
        public void TestRevertOrder()
        {
            var incomeSumBefore = _incomesForProduct.Sum(x => x.QuantityCurrent);

            var outcome1 = new Outcome(_product.Price, 10, _incomesForProduct[0], 0);
            var outcome2 = new Outcome(_product.Price, 5, _incomesForProduct[1], 0);
            var outcomes = new List<Outcome>() {outcome1, outcome2};
            var orderLine = new OrderLine(_product, 15, outcomes);

            _incomesForProduct[0].QuantityCurrent -= 10;
            _incomesForProduct[0].QuantityCurrent -= 5;

            Order order = new Order(outcomes, new List<OrderLine>(){orderLine});

            Assert.True(order.Outcomes().Sum(x => x.Quantity) == 15);

            _orderService.RevertOrder(order);

            Assert.True(_incomesForProduct.Sum(x => x.QuantityCurrent) == incomeSumBefore);
            Assert.True(order.Outcomes().Count() == 0);
            Assert.True(order.Status.Equals(OrderStatus.Revoked));
        }
Esempio n. 5
0
        public void AddOrders()
        {
            return;
            ISession session = GetConfiguration().BuildSessionFactory().OpenSession();
            IList<User> users = session.CreateCriteria(typeof(User)).List<User>();
            IList<Product> products = session.CreateCriteria(typeof(Product)).List<Product>();
            Random r = new Random();
            foreach (User user in users)
            {
                if (user.Email.Contains("11")) continue;
                if (user.Email.Contains("22")) continue;
                if (user.Email.Contains("44")) continue;
                if (user.Email.Contains("55")) continue;
                if (user.Email.Contains("66")) continue;
                if (user.Email.Contains("88")) continue;

                int n = r.Next(2, 20);
                for (int i = 0; i < n; i++)
                {
                    Order order = new Order(null, null);
                    order.User = user;
                    order.DeliverType = (DeliverType)r.Next(3);
                    order.PaymentType = (PaymentType)r.Next(2);
                    order.ShippingDetails = user.Contact;

                    order.Date = new DateTime(2005 + r.Next(5), r.Next(1, 12), r.Next(1, 28), r.Next(0, 23), r.Next(0, 59), r.Next(0, 59));
                    int p = r.Next(1, 7);
                    for (int j = 0; j < p; j++)
                    {
                        order.AddOrderLine(products[r.Next(products.Count)], r.Next(1, 10), null);
                    }
                    session.Save(order);
                    order.Uid = session.Get<UniqueId>(order.Id).Uid;
                    session.Save(order);

                }
            }
            session.Flush();
        }
Esempio n. 6
0
 public void RevertOrder(Order order)
 {
     IEnumerable<Outcome> outcomes = order.Outcomes();
     foreach (Outcome outcome in outcomes)
     {
         outcome.Income.QuantityCurrent += outcome.Quantity;
     }
     order.ClearOutcomes();
     order.Status = OrderStatus.Revoked;
 }
Esempio n. 7
0
 public void NotifyUser(Order order, ControllerContext context)
 {
     string message = MailService.RenderViewToString("~/Views/MailTemplates/OrderStatusChanged.aspx", order, context);
     MailService.Send("Elfam.ru - Уведомление", message, order.User.Email);
 }