public ActionResult DeleteConfirmed(int id)
        {
            Dishes_Products dishes_Products = db.Dishes_Products.Find(id);

            db.Dishes_Products.Remove(dishes_Products);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(GlobalModel list, [Bind(Include = "Id,Name,Date,Calories,Proteins,Carbohydrates,Fats")] Dishes dishes)
        {
            var   selectedProducts = list.Products.Where(x => x.Volume > 0).ToList <Product>();
            float calories = 0, carbo = 0, proteins = 0, fats = 0;

            foreach (Product p in selectedProducts)
            {
                calories += p.Calories * p.Volume / 100;
                carbo    += p.Carbohydrates * p.Volume / 100;
                proteins += p.Proteins * p.Volume / 100;
                fats     += p.Fats * p.Volume / 100;
            }

            dishes.Calories      = calories;
            dishes.Carbohydrates = carbo;
            dishes.Proteins      = proteins;
            dishes.Fats          = fats;
            dishes.Date          = System.DateTime.Now;
            dishes.UserId        = System.Web.HttpContext.Current.User.Identity.GetUserId();

            db.Dishes.Add(dishes);
            db.SaveChanges();

            int id = dishes.Id;



            foreach (Product p in selectedProducts)
            {
                Dishes_Products dishesProducts = new Dishes_Products();
                dishesProducts.Id_Dishes = id;

                dishesProducts.Id_Product = p.Id;
                dishesProducts.gram       = p.Volume;

                db.Dishes_Products.Add(dishesProducts);
                db.SaveChanges();
            }

            {
                var selected = db.Dishes_Products.Where(x => x.Id_Dishes == list.Id).ToList <Dishes_Products>();
                foreach (Dishes_Products d in selected)
                {
                    db.Dishes_Products.Remove(d);
                    db.SaveChanges();
                }

                Dishes dishesD = db.Dishes.Find(list.Id);
                db.Dishes.Remove(dishesD);
                db.SaveChanges();
            }



            return(RedirectToAction("Index", "Dishes_Products"));
        }
        public ActionResult Create2([Bind(Include = "Id_Dishes,Id_Product,gram")] Dishes_Products dishes_Products)
        {
            if (ModelState.IsValid)
            {
                db.Dishes_Products.Add(dishes_Products);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dishes_Products));
        }