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)); } }
//private DBingredient db = new DBingredient(); // GET: Boodschap public ActionResult Index() { User user = (User)Session["user"]; if (user == null) { return(RedirectToAction("Index", "User")); } //DBingredient context = new DBingredient(); using (DBingredient context = new DBingredient()) { int boodschapLijstID = user.boodschapLijst.BoodschapLijstID; BoodschapLijst boodschapLijst = context.BoodschapLijsts.Find(boodschapLijstID); //List<BoodschapIngredient> lijst = context.BoodschapIngredients.ToList(); if (boodschapLijst != null) { foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients) { int ingredientID = boodschapIngredient.ingredient.ingredientID; Ingredient ig = context.Ingredients.Find(ingredientID); boodschapIngredient.ingredient = ig; } return(View(boodschapLijst.BoodschapIngredients)); } return(View()); } }
// GET api/values/5 public IEnumerable <BoodschapIngredientModel> Get(int id) { List <BoodschapIngredient> boodschapLijst = new List <BoodschapIngredient>(); List <BoodschapIngredientModel> boodschapModelLijst = new List <BoodschapIngredientModel>(); using (DBingredient context = new DBingredient()) { User user = context.Users.Find(id); int boodschapLijstID = user.boodschapLijst.BoodschapLijstID; BoodschapLijst boodschaplijstUser = context.BoodschapLijsts.Find(boodschapLijstID); boodschapLijst = boodschaplijstUser.BoodschapIngredients; foreach (BoodschapIngredient boodschapIngredient in boodschapLijst) { BoodschapIngredientModel model = new BoodschapIngredientModel(); model.BoodschapIngredientID = boodschapIngredient.BoodschapIngredientID; model.naam = boodschapIngredient.ingredient.name; model.merk = boodschapIngredient.ingredient.merk; model.Hoeveelheid = boodschapIngredient.Hoeveelheid; model.Eenheid = boodschapIngredient.Eenheid; boodschapModelLijst.Add(model); } } return(boodschapModelLijst); }
// GET: Ingredients/Delete/5 public ActionResult Delete(int?id) { correctUser = false; //DBingredient context = new DBingredient(); using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Recipe recipe = context.Recipes.Find(id); if (recipe == null) { return(HttpNotFound()); } int userID = recipe.user.UserID; User user = context.Users.Find(userID); recipe.user = user; User currentUser = (User)Session["user"]; if (recipe.user.UserID == currentUser.UserID) { correctUser = true; } ViewBag.User = correctUser; //List<RecipeIngredient> lijst = new List<RecipeIngredient>(); return(View(recipe)); } }
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 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 EditRecipe(int?id) { using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Recipe recipe = context.Recipes.Find(id); if (recipe == null) { return(HttpNotFound()); } int userID = recipe.user.UserID; recipe.user = context.Users.Find(userID); List <RecipeIngredient> lijst = new List <RecipeIngredient>(); foreach (RecipeIngredient recipeIngredient in recipe.RecipeIngredients) { int recipeIngredientID = recipeIngredient.RecipeIngredientID; RecipeIngredient foundIngredient = context.TotalRecipeIngredients.Find(recipeIngredientID); lijst.Add(foundIngredient); } //TempData["recipeIngredients"] = lijst; recipe.RecipeIngredients = lijst; return(View(recipe)); } }
public ActionResult AddIngredient(int?id) { correctUser = false; using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Recipe recipe = context.Recipes.Find(id); if (recipe == null) { return(HttpNotFound()); } TempData["recipe"] = recipe; int userID = recipe.user.UserID; User user = context.Users.Find(userID); recipe.user = user; User currentUser = (User)Session["user"]; if (recipe.user.UserID == currentUser.UserID) { correctUser = true; } ViewBag.User = correctUser; return(View()); } }
// GET: Ingredients/Create public ActionResult Toevoegen() { using (DBingredient context = new DBingredient()) { return(View()); } }
// GET: Ingredients/Create public ActionResult Create() { using (DBingredient context = new DBingredient()) { return(View()); } }
//private DBingredient db = new DBingredient(); // GET: Inventory public ActionResult Index() { User user = (User)Session["user"]; if (user == null) { return(RedirectToAction("Index", "User")); } using (DBingredient context = new DBingredient()) { int inventoryID = user.inventory.InventoryID; Inventory inventory = context.Inventories.Find(inventoryID); //List<InventoryIngredient> lijst = context.Users.Fin; if (inventory != null) { foreach (InventoryIngredient inventoryIngredient in inventory.InventoryIngredients) { int ingredientID = inventoryIngredient.ingredient.ingredientID; Ingredient ig = context.Ingredients.Find(ingredientID); inventoryIngredient.ingredient = ig; } return(View(inventory.InventoryIngredients)); } return(View()); } }
// GET api/values public IEnumerable <BoodschapIngredientModel> Get() { List <BoodschapIngredient> boodschapLijst = new List <BoodschapIngredient>(); List <BoodschapIngredientModel> boodschapModelLijst = new List <BoodschapIngredientModel>(); using (DBingredient context = new DBingredient()) { boodschapLijst = context.BoodschapIngredients.ToList(); foreach (BoodschapIngredient boodschapIngredient in boodschapLijst) { BoodschapIngredientModel model = new BoodschapIngredientModel(); model.BoodschapIngredientID = boodschapIngredient.BoodschapIngredientID; model.naam = boodschapIngredient.ingredient.name; model.merk = boodschapIngredient.ingredient.merk; model.Hoeveelheid = boodschapIngredient.Hoeveelheid; model.Eenheid = boodschapIngredient.Eenheid; boodschapModelLijst.Add(model); } } return(boodschapModelLijst); }
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")); } }
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)); } }
// GET: Ingredients/Create public ActionResult Create() { //User user = (User)Session["user"]; //if (user == null) //{ // return RedirectToAction("Index", "User"); //} using (DBingredient context = new DBingredient()) { return(View()); } }
public ActionResult AddRecipeIngredient(int?id) { using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RecipeIngredient recipeIngredient = new RecipeIngredient(); recipeIngredient.ingredient = context.Ingredients.Find(id); return(View(recipeIngredient)); } }
public ActionResult AddIngredient(string naam) { DBingredient context = new DBingredient(); Recipe recipe = ViewBag.Recipe; List <Ingredient> lijst = context.Ingredients.ToList <Ingredient>(); correctUser = true; ViewBag.User = correctUser; List <Ingredient> filter = lijst.Where(e => e.name.Contains(naam)).ToList(); //ViewBag.lijst = filter; return(View(filter)); }
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 Details(int?id) { correctUser = false; using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Recipe recipe = context.Recipes.Find(id); if (recipe == null) { return(HttpNotFound()); } int userID = recipe.user.UserID; User user = context.Users.Find(userID); recipe.user = user; List <RecipeIngredient> lijst = new List <RecipeIngredient>(); foreach (RecipeIngredient recipeIngredient in recipe.RecipeIngredients) { int recipeIngredientID = recipeIngredient.RecipeIngredientID; RecipeIngredient recipeIngredientLijst = context.TotalRecipeIngredients.Find(recipeIngredientID); int ingredientID = recipeIngredientLijst.ingredient.ingredientID; Ingredient ingredientLijst = context.Ingredients.Find(ingredientID); recipeIngredientLijst.ingredient = ingredientLijst; lijst.Add(recipeIngredientLijst); } User currentUser = (User)Session["user"]; if (recipe.user.UserID == currentUser.UserID) { correctUser = true; } ViewBag.User = correctUser; recipe.RecipeIngredients = lijst; ViewBag.Lijst = lijst; TempData["RecipeID"] = recipe.RecipeID; return(View(recipe)); } }
// GET: Ingredients/Edit/5 public ActionResult Edit(int?id) { using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ingredient ingredient = context.Ingredients.Find(id); if (ingredient == null) { return(HttpNotFound()); } return(View(ingredient)); } }
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()); } }
public ActionResult PrintConfirmed() { using (DBingredient context = new DBingredient()) { User user = (User)Session["user"]; int boodschapLijstID = user.boodschapLijst.BoodschapLijstID; BoodschapLijst boodschapLijst = context.BoodschapLijsts.Find(boodschapLijstID); string filePath = @"C:\Users\Public\BoodschappenLijst.txt"; string[] lijnen = new string[boodschapLijst.BoodschapIngredients.Count + 1]; int arraycount = 0; if (boodschapLijst != null) { lijnen[0] = "Naam Merk Hoeveelheid Eenheid"; foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients) { arraycount = arraycount + 1; lijnen[arraycount] = $"{boodschapIngredient.ingredient.name} {boodschapIngredient.ingredient.merk} {boodschapIngredient.Hoeveelheid} {boodschapIngredient.Eenheid}"; //int ingredientID = boodschapIngredient.ingredient.ingredientID; //Ingredient ig = context.Ingredients.Find(ingredientID); //boodschapIngredient.ingredient = ig; } try { System.IO.File.WriteAllLines(filePath, lijnen); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(RedirectToAction("Index")); } return(View()); } }
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 AddInventory(int?id) { using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } BoodschapIngredient boodschapIngredient = new BoodschapIngredient(); boodschapIngredient.ingredient = context.Ingredients.Find(id); ViewBag.IngredientID = id; return(View(boodschapIngredient)); } }
public ActionResult Index(string input) { User user = (User)Session["user"]; if (user == null) { return(RedirectToAction("Index", "User")); } using (DBingredient context = new DBingredient()) { int inventoryID = user.inventory.InventoryID; Inventory inventory = context.Inventories.Find(inventoryID); //List<InventoryIngredient> lijst = context.Users.Fin; if (inventory != null) { foreach (InventoryIngredient inventoryIngredient in inventory.InventoryIngredients) { int ingredientID = inventoryIngredient.ingredient.ingredientID; Ingredient ig = context.Ingredients.Find(ingredientID); inventoryIngredient.ingredient = ig; } List <InventoryIngredient> filter = inventory.InventoryIngredients.Where(e => e.ingredient.name.Contains(input)).ToList(); List <InventoryIngredient> filter2 = inventory.InventoryIngredients.Where(e => e.ingredient.merk.Contains(input)).ToList(); foreach (InventoryIngredient inventoryingredient2 in filter2) { int ID = inventoryingredient2.InventoryIngredientID; if (!filter.Exists(x => x.InventoryIngredientID == ID)) { filter.Add(inventoryingredient2); } } return(View(filter)); } return(View()); } }
public ActionResult Index(string input) { User user = (User)Session["user"]; if (user == null) { return(RedirectToAction("Index", "User")); } using (DBingredient context = new DBingredient()) { int boodschapLijstID = user.boodschapLijst.BoodschapLijstID; BoodschapLijst boodschapLijst = context.BoodschapLijsts.Find(boodschapLijstID); //List<InventoryIngredient> lijst = context.Users.Fin; if (boodschapLijst != null) { foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients) { int ingredientID = boodschapIngredient.ingredient.ingredientID; Ingredient ig = context.Ingredients.Find(ingredientID); boodschapIngredient.ingredient = ig; } List <BoodschapIngredient> filterNaam = boodschapLijst.BoodschapIngredients.Where(e => e.ingredient.name.Contains(input)).ToList(); List <BoodschapIngredient> filterMerk = boodschapLijst.BoodschapIngredients.Where(e => e.ingredient.merk.Contains(input)).ToList(); foreach (BoodschapIngredient boodschapIngredient2 in filterMerk) { int ID = boodschapIngredient2.BoodschapIngredientID; if (!filterNaam.Exists(x => x.BoodschapIngredientID == ID)) { filterNaam.Add(boodschapIngredient2); } } return(View(filterNaam)); } return(View()); } }
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 Index(string input) { using (DBingredient context = new DBingredient()) { List <Ingredient> lijstIngredients = context.Ingredients.ToList(); List <Ingredient> filterNaam = lijstIngredients.Where(e => e.name.Contains(input)).ToList(); List <Ingredient> filterMerk = lijstIngredients.Where(e => e.merk.Contains(input)).ToList(); foreach (Ingredient ingredient in filterMerk) { int ID = ingredient.ingredientID; if (!filterNaam.Exists(x => x.ingredientID == ID)) { filterNaam.Add(ingredient); } } return(View(filterNaam)); } }
// GET: Ingredients/Edit/5 public ActionResult Edit(int?id) { //DBingredient context = new DBingredient(); using (DBingredient context = new DBingredient()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BoodschapIngredient boodschapIngredient = context.BoodschapIngredients.Find(id); if (boodschapIngredient == null) { return(HttpNotFound()); } int ingredientID = boodschapIngredient.ingredient.ingredientID; Ingredient ig = context.Ingredients.Find(ingredientID); boodschapIngredient.ingredient = ig; return(View(boodschapIngredient)); } }