Exemplo n.º 1
0
 public ActionResult Index(DeliverPrices prices)
 {
     if (!ModelState.IsValid)
     {
         return(View(prices));
     }
     prices.Id = 1;
     daoTemplate.Save(prices);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        public decimal GetPrice(DeliverType deliverType)
        {
            DeliverPrices prices = _daoTemplate.FindAll <DeliverPrices>()[0];

            if (deliverType == DeliverType.CourierMoscow)
            {
                return(prices.CourierMoscow);
            }
            if (deliverType == DeliverType.CourierSubMoscow)
            {
                return(prices.CourierSubMoscow);
            }
            if (deliverType == DeliverType.Post)
            {
                return(prices.Post);
            }
            //if (deliverType == DeliverType.Myself)
            return(prices.Self);
        }
Exemplo 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
            });
        }
Exemplo n.º 4
0
        public void AddUsers()
        {
            string[] cities   = { "Москва", "Калуга", "Тула", "Брянск" };
            string[] streets  = { "Ленина", "Кирова", "Московская", "Чичерина" };
            string[] domens   = { "mail.ru", "gmail.com", "yandex.ru" };
            string[] nicks    = { "vasya", "jane", "oleg" };
            string[] surnames = { "Аверин", "Дуров", "Медведев", "Тихонов", "Кузнецов" };
            string[] names    = { "Андрей", "Денис", "Михаил", "Анатолий", "Кирилл" };

            using (ISession session = GetConfiguration().BuildSessionFactory().OpenSession())
            {
                Contact contact = new Contact()
                {
                    City    = "Калуга",
                    Country = "РФ",
                    House   = "18",
                    Name    = "Алексей",
                    Phone   = "555-939",
                    Region  = "Калужская обл.",
                    Room    = "21",
                    Surname = "Покревский",
                    Street  = "Чичерина",
                    Zip     = "248010"
                };

                DeliverPrices prices = new DeliverPrices()
                {
                    CourierMoscow    = 250,
                    CourierSubMoscow = 300,
                    Post             = 170,
                    Self             = 0
                };
                session.Save(prices);

                User user = new User()
                {
                    Contact = contact, Email = "*****@*****.**", Role = Role.Admin
                };
                user.PasswordHash = UserService.CalculateHash("1");
                session.Save(user);
                session.Flush();
                //return;
                Random r = new Random();
                int    n = r.Next(5, 10);
                for (int i = 0; i < 11; i++)
                {
                    contact = new Contact()
                    {
                        City    = cities[r.Next(cities.Length)],
                        Country = "РФ",
                        House   = r.Next(1, 99) + "",
                        Name    = names[r.Next(names.Length)],
                        Phone   = string.Format("{0}({1}){2}-{3}-{4}", r.Next(1, 9), r.Next(100, 999), r.Next(100, 999), r.Next(10, 99), r.Next(10, 99)),
                        Region  = "Калужская обл.",
                        Room    = r.Next(1, 99) + "",
                        Surname = surnames[r.Next(surnames.Length)],
                        Street  = streets[r.Next(streets.Length)],
                        Zip     = "ABCDF"
                    };
                    User user1 = new User()
                    {
                        Contact  = contact,
                        Email    = string.Format("{0}{2}@{1}", nicks[r.Next(nicks.Length)], domens[r.Next(domens.Length)], i),
                        Role     = Role.User,
                        Discount = r.Next(5) * 100
                    };
                    user1.PasswordHash = UserService.CalculateHash("1");
                    session.Save(user1);
                    session.Flush();
                }
            }
        }