Пример #1
0
 public static OrderShippingInfo From(EnterShippingDetailsViewModel viewModel)
 {
     OrderShippingInfo info = new OrderShippingInfo();            
     info.Contact = Contact.From(viewModel.Contact);
     info.DeliverType = viewModel.DeliverType;
     info.PaymentType = viewModel.PaymentType;
     info.Comment = viewModel.Comment;
     
     return info;
 }
Пример #2
0
        public static OrderShippingInfo From(EnterShippingDetailsViewModel viewModel)
        {
            OrderShippingInfo info = new OrderShippingInfo();

            info.Contact     = Contact.From(viewModel.Contact);
            info.DeliverType = viewModel.DeliverType;
            info.PaymentType = viewModel.PaymentType;
            info.Comment     = viewModel.Comment;

            return(info);
        }
Пример #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};
        }
Пример #4
0
        public void SetUp()
        {
            _product = new Product() { Id = 1 };

            _incomesForProduct = new List<Income>
                                     {
                                         new Income()
                                             {
                                                 BuyPrice = 10,
                                                 Date = new DateTime(2000, 6, 28),
                                                 Id = 1,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 20,
                                                 Date = new DateTime(2000, 5, 28),
                                                 Id = 2,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 30,
                                                 Date = new DateTime(2000, 4, 28),
                                                 Id = 3,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 40,
                                                 Date = new DateTime(2000, 3, 28),
                                                 Id = 4,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                         new Income()
                                             {
                                                 BuyPrice = 50,
                                                 Date = new DateTime(2000, 2, 28),
                                                 Id = 5,
                                                 Product = _product,
                                                 QuantityCurrent = 10,
                                                 QuantityInital = 10
                                             },
                                     };

            _emptyIncome = new Income()
                               {
                                   BuyPrice = 50,
                                   Date = new DateTime(1980, 2, 28),
                                   Id = 6,
                                   Product = _product,
                                   QuantityCurrent = 0,
                                   QuantityInital = 0
                               };
            _incomesForProduct.Add(_emptyIncome);
            _product.Incomes = _incomesForProduct;

            _cartItems = new List<CartItem>
                             {
                                 new CartItem() {Product = _product, Quantity = 33}
                             };
            _user = new User() { };
            _shippingInfo = new OrderShippingInfo() { };

            _daoTemplate = new Mock<IDaoTemplate>();
            _daoTemplate.Setup(x => x.FindByID<Product>(1)).Returns(_product);
            _daoTemplate.Setup(x => x.FindByID<UniqueId>(0)).Returns(new UniqueId() { Uid = 123 });

            _orderService = new OrderService();
            _orderService.DaoTemplate = _daoTemplate.Object;
        }
Пример #5
0
//        public virtual decimal Profit()
//        {
//            return Outcomes().Sum(o => o.Profit);
//        }


        public virtual void CopyFrom(OrderShippingInfo info)
        {
            DeliverType     = info.DeliverType;
            PaymentType     = info.PaymentType;
            ShippingDetails = info.Contact;
        }
Пример #6
0
 //        public virtual decimal Profit()
 //        {
 //            return Outcomes().Sum(o => o.Profit);
 //        }
 public virtual void CopyFrom(OrderShippingInfo info)
 {
     DeliverType = info.DeliverType;
     PaymentType = info.PaymentType;
     ShippingDetails = info.Contact;
 }