public ActionResult AddInventory([Bind(Include = "InventoryingredientID,ingredient,Hoeveelheid,Eenheid")] InventoryIngredient inventoryIngredient)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    User user      = (User)Session["user"];
                    int  UserID    = user.UserID;
                    User indexUser = context.Users.Find(UserID);
                    //int inventoryID = indexUser.inventory.InventoryID;

                    //Inventory inventory = context.Inventories.Find(inventoryID);
                    Ingredient ig = context.Ingredients.Find(inventoryIngredient.ingredient.ingredientID);
                    inventoryIngredient.ingredient = ig;
                    context.InventoryIngredients.Add(inventoryIngredient);
                    context.SaveChanges();

                    indexUser.inventory.InventoryIngredients.Add(inventoryIngredient);
                    context.Entry(indexUser.inventory).State = EntityState.Modified;
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(inventoryIngredient));
            }
        }
        public ActionResult DeleteConfirmedEdit(int id)
        {
            using (DBingredient context = new DBingredient())
            {
                int?recipeIDInput = (int)TempData["RecipeID"];

                if (recipeIDInput == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                Recipe recipe = context.Recipes.Find(recipeIDInput);

                if (recipe == null)
                {
                    return(HttpNotFound());
                }

                RecipeIngredient ingredient = context.TotalRecipeIngredients.Find(id);
                recipe.RecipeIngredients.Remove(ingredient);
                context.Entry(recipe).State = EntityState.Modified;
                context.SaveChanges();

                context.TotalRecipeIngredients.Remove(ingredient);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult AddRecipeIngredient([Bind(Include = "RecipeIngredientID,ingredient,Hoeveelheid,Eenheid")] RecipeIngredient recipeIngredient)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    //User user = (User)Session["user"];
                    //int UserID = user.UserID;
                    //User indexUser = context.Users.Find(UserID);
                    //int inventoryID = indexUser.inventory.InventoryID;

                    //Inventory inventory = context.Inventories.Find(inventoryID);
                    Ingredient ig = context.Ingredients.Find(recipeIngredient.ingredient.ingredientID);
                    recipeIngredient.ingredient = ig;
                    context.TotalRecipeIngredients.Add(recipeIngredient);
                    context.SaveChanges();

                    Recipe tempRecipe = (Recipe)TempData["recipe"];
                    int    recipeID   = tempRecipe.RecipeID;
                    Recipe recipe     = context.Recipes.Find(recipeID);
                    recipe.RecipeIngredients.Add(recipeIngredient);
                    //context.Entry(recipe.RecipeIngredients).State = EntityState.Modified;
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(recipeIngredient));
            }
        }
Example #4
0
        public ActionResult Create([Bind(Include = "ingredientID,name,merk")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                db.Ingredients.Add(ingredient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ingredient));
        }
 public ActionResult Create([Bind(Include = "RecipeID,Naam,Beschrijving,Calorien")] Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         db.Recipes.Add(recipe);
         db.SaveChanges();
         return(RedirectToAction("AddIngredient", recipe));
     }
     ViewBag.Recipe = recipe;
     return(View());
 }
        public ActionResult AddInventory([Bind(Include = "InventoryingredientID,ingredient,Hoeveelheid,Eenheid")] InventoryIngredient inventoryIngredient)
        {
            if (ModelState.IsValid)
            {
                Ingredient ig = db.Ingredients.Find(inventoryIngredient.ingredient.ingredientID);
                inventoryIngredient.ingredient = ig;
                db.InventoryIngredients.Add(inventoryIngredient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(inventoryIngredient));
        }
Example #7
0
 public ActionResult DeleteConfirmed(int id)
 {
     using (DBingredient context = new DBingredient())
     {
         Ingredient ingredient = context.Ingredients.Find(id);
         context.Ingredients.Remove(ingredient);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Example #8
0
 public ActionResult Edit([Bind(Include = "ingredientID,name,merk")] Ingredient ingredient)
 {
     using (DBingredient context = new DBingredient())
     {
         if (ModelState.IsValid)
         {
             context.Entry(ingredient).State = EntityState.Modified;
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(ingredient));
     }
 }
Example #9
0
        public ActionResult Create([Bind(Include = "ingredientID,name,merk")] Ingredient ingredient)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    context.Ingredients.Add(ingredient);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(ingredient));
            }
        }
 public ActionResult Edit([Bind(Include = "BoodschapIngredientID,Ingredient,Hoeveelheid,Eenheid")] BoodschapIngredient boodschapIngredient)
 {
     using (DBingredient context = new DBingredient())
     {
         if (ModelState.IsValid)
         {
             Ingredient ig = context.Ingredients.Find(boodschapIngredient.ingredient.ingredientID);
             boodschapIngredient.ingredient           = ig;
             context.Entry(boodschapIngredient).State = EntityState.Modified;
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(boodschapIngredient));
     }
 }
 public ActionResult Create([Bind(Include = "RecipeID,Naam,Beschrijving,Calorien")] Recipe recipe)
 {
     using (DBingredient context = new DBingredient())
     {
         if (ModelState.IsValid)
         {
             User user   = (User)Session["user"];
             int  userID = user.UserID;
             recipe.user = context.Users.Find(userID);
             context.Recipes.Add(recipe);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.Recipe = recipe;
         return(View());
     }
 }
Example #12
0
        public ActionResult Create([Bind(Include = "UserID,inlognaam,wachtwoord")] User user)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    Inventory      inventory      = new Inventory();
                    BoodschapLijst boodschapLijst = new BoodschapLijst();
                    user.inventory      = inventory;
                    user.boodschapLijst = boodschapLijst;
                    context.Users.Add(user);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(user));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            using (DBingredient context = new DBingredient())
            {
                Recipe recipe = context.Recipes.Find(id);
                List <RecipeIngredient> lijst = new List <RecipeIngredient>();
                lijst = recipe.RecipeIngredients;
                foreach (RecipeIngredient recipeIngredient in lijst.ToList())
                {
                    int recipeIngredientID            = recipeIngredient.RecipeIngredientID;
                    RecipeIngredient removeIngredient = context.TotalRecipeIngredients.Find(recipeIngredientID);
                    context.TotalRecipeIngredients.Remove(removeIngredient);
                }

                context.Recipes.Remove(recipe);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult EditRecipe([Bind(Include = "RecipeID,user,Naam,Beschrijving,Calorien")] Recipe recipe)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    int    recipeID  = recipe.RecipeID;
                    Recipe origineel = context.Recipes.Find(recipeID);
                    recipe.RecipeIngredients = origineel.RecipeIngredients;
                    int  userID = recipe.user.UserID;
                    User user   = context.Users.Find(userID);
                    recipe.user = user;

                    context.Set <Recipe>().AddOrUpdate(recipe);

                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(recipe));
            }
        }
        public ActionResult Gekocht(int?id)
        {
            using (DBingredient context = new DBingredient())
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                BoodschapIngredient boodschapIngredient = context.BoodschapIngredients.Find(id);
                if (boodschapIngredient == null)
                {
                    return(HttpNotFound());
                }

                User user = (User)Session["user"];

                InventoryIngredient inventoryIngredient = new InventoryIngredient();
                inventoryIngredient.ingredient  = boodschapIngredient.ingredient;
                inventoryIngredient.Hoeveelheid = boodschapIngredient.Hoeveelheid;
                inventoryIngredient.Eenheid     = boodschapIngredient.Eenheid;

                int            inventoryID      = user.inventory.InventoryID;
                Inventory      inventory        = context.Inventories.Find(inventoryID);
                int            boodschapLijstID = user.boodschapLijst.BoodschapLijstID;
                BoodschapLijst boodschapLijst   = context.BoodschapLijsts.Find(boodschapLijstID);

                inventory.InventoryIngredients.Add(inventoryIngredient);
                //context.Entry(inventory.InventoryIngredients).State = EntityState.Modified;

                boodschapLijst.BoodschapIngredients.Remove(boodschapIngredient);
                //context.Entry(user.boodschapLijst).State = EntityState.Modified;

                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }