Beispiel #1
0
        public ActionResult RequestPrices()
        {
            List<IngredientNotify> objingrToNotifyList = new List<IngredientNotify>();

            var objNotify = new Notification();
            objNotify.DateCreated = DateTime.Now;
            objNotify.RestaurantId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            foreach (IndexIngredientsToNotify ingToN in GetIngredientsToCalculate().Lines)
            {
                if (GetDishesToCalculate().Lines.Count() > 0)
                {
                    foreach (var i in GetDishesToCalculate().Lines)
                    {

                        foreach (var ix in i.objDish.IngredientDishes.Where(c => c.IngredientDishId == ingToN.IngredientDishId))
                        {

                            objingrToNotifyList.Add(new IngredientNotify()
                            {

                                IngredientDishId = ingToN.IngredientDishId,
                                Unit = db.Units.Where(x => x.UnitId == ix.UnitId).FirstOrDefault(),
                                Ingredient = db.Ingredients.Where(x => x.IngredientId == ingToN.IngredientId).FirstOrDefault(),
                                Required = ingToN.Required,
                                Inventory = ix.Ingredient.QuantityInventory.GetValueOrDefault(),
                                TotalRequired = ingToN.TotalRequired,
                                DateCreated = DateTime.Now,
                                isActive = true

                            });
                        }
                    }
                }
                else {

                    objingrToNotifyList.Add(new IngredientNotify()
                    {

                        Unit = db.Units.Where(x => x.Name == ingToN.UnitName).FirstOrDefault(),
                        Ingredient = db.Ingredients.Where(x => x.IngredientId == ingToN.IngredientId).FirstOrDefault(),
                        Required = 0,
                        Inventory = db.Ingredients.Where(x => x.Name == ingToN.IngredientDishName).FirstOrDefault().QuantityInventory.GetValueOrDefault(),
                        TotalRequired = ingToN.TotalRequired,
                        DateCreated = DateTime.Now,
                        isActive = true

                        });

                }

            }

            foreach (IngredientNotify ingToN in objingrToNotifyList)
            {

                objNotify.IngredientNotifies.Add(ingToN);

            }

            db.Notifications.Add(objNotify);
            db.SaveChanges();

            GetDishesToCalculate().Clear();
            GetIngredientsToCalculate().Clear();

            return RedirectToAction("Index","Notifications", new { sent  = true} );
        }
Beispiel #2
0
        public ActionResult RequestPrices()
        {
            List<IngredientNotify> objingrToNotifyList = new List<IngredientNotify>();

            var objNotify = new Notification();
            objNotify.DateCreated = DateTime.Now;

            foreach (var i in GetDishesToCalculate().Lines)
            {

                foreach (var ix in i.objDish.IngredientDishes)
                {

                    var objNL = objingrToNotifyList.Where(x => x.Ingredient.Name == ix.Name).FirstOrDefault();

                    if (objNL == null)
                    {
                        objingrToNotifyList.Add(new IngredientNotify()
                        {

                            IngredientDishId = ix.IngredientDishId,
                            Unit = db.Units.Where(x => x.UnitId == ix.UnitId).FirstOrDefault(),
                            Ingredient = db.Ingredients.Where(x => x.IngredientId == ix.Ingredient.IngredientId).FirstOrDefault(),
                            Required = ix.QuantityNeeded,
                            Inventory = ix.Ingredient.QuantityInventory.GetValueOrDefault(),
                            TotalRequired = ix.QuantityNeeded - ix.Ingredient.QuantityInventory.GetValueOrDefault(),
                            DateCreated = DateTime.Now,
                            isActive = true

                        }
                           );

                    }
                    else
                    {

                        objNL.Required = objNL.Required + ix.QuantityNeeded;
                        objNL.TotalRequired = objNL.Required - ix.Ingredient.QuantityInventory.GetValueOrDefault();

                    }

                }

            }

            foreach (IngredientNotify ingToN in objingrToNotifyList)
            {

                objNotify.IngredientNotifies.Add(ingToN);

            }

            db.Notifications.Add(objNotify);
            db.SaveChanges();

            GetDishesToCalculate().Clear();
             //   GetDish().Clear();

            return RedirectToAction("Index");
        }