示例#1
0
        // GET: Orders/Create
        public ActionResult Create()
        {
            DishSelect dishSelect = db.DishSelects.Get(db.DishSelects.Count());

            _order.DishPrice  = dishSelect.price;
            _order.DishAmount = dishSelect.DishesAmount;
            _order.DishName   = dishSelect.Name;

            return(View(_order));
        }
示例#2
0
        public ActionResult Buy(Order _ord)
        {
            DishSelect dishSelect = db.DishSelects.Get(db.DishSelects.Count());

            _ord.DishSelectId = dishSelect.Id;
            _ord.DishName     = dishSelect.Name;
            _ord.DishAmount   = dishSelect.DishesAmount;
            _ord.DishPrice    = dishSelect.price;
            var ClientsList = db.Clients.GetList();

            foreach (var client in ClientsList)
            {
                if ((client.email == _ord.Client.email) && (client.NumberPhone == _ord.Client.NumberPhone))
                {
                    _ord.ClientId = client.Id;
                    _ord.Client   = null;
                    break;
                }
            }

            //Вычитаем продукты со склада
            foreach (Ingredient _ingredient in dishSelect.Ingredients)
            {
                Product p = db.Products.Get((int)_ingredient.ProductId);
                p.Balance = p.Balance - (_ingredient.quantity * dishSelect.DishesAmount);
                db.Products.Update(p);
            }
            //Если превышен лимит минимального остатка продуктов => формируем заказ

            foreach (Ingredient _ingredient in dishSelect.Ingredients)
            {
                Product p = db.Products.Get((int)_ingredient.ProductId);
                if (p.Balance < p.MinBalance)
                {
                    _OrderTP.Ingredients.Add(new Ingredient()
                    {
                        price = p.SellPrice, ProductId = p.Id, productName = p.Name, quantity = p.MinBalance
                    });
                    _OrderTP.Message += "Закончился товар - " + p.Name + ", везите ещё;";
                }
            }
            _OrderTP.TotalPrice = GetTotalPrice();
            if (_OrderTP.Ingredients.Count() > 0)
            {
                db.OrdersToProvisioner.Create(_OrderTP);
            }

            db.Orders.Create(_ord);
            db.Save();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public ActionResult SelectDish(DishSelect ds)
 {
     db.DishSelects.Create(DishSelectView);
     db.Save();
     return(RedirectToAction("Create", "Orders"));
 }