public ActionResult Edit(int id, RecipeDetailsModel updated) { if (ModelState.IsValid) { ro.UpdateRecipe(id, updated); return RedirectToAction("FullDetails", new { id = id }); } else { return View(updated); } }
public ActionResult Submit(RecipeDetailsModel r) { if (ModelState.IsValid) { var id = ro.AddRecipe(r); return RedirectToAction("FullDetails", new { id = id }); } else { return View(r); } }
public void UpdateRecipe(int id, RecipeDetailsModel updated) { using (var db = new RecipesEntities()) { var dbRecipe = db.Recipes.Where(r => r.ID == id).First(); dbRecipe.Name = updated.Name; dbRecipe.Summary = updated.Summary; dbRecipe.CookingTime = updated.CookingTimeInMinutes; dbRecipe.Ingredients = updated.Ingredients; dbRecipe.Instructions = updated.Instructions; db.SaveChanges(); } }
public int AddRecipe(RecipeDetailsModel r) { using (var db = new RecipesEntities()) { var toAdd = new Recipes { Name = r.Name, Summary = r.Summary, CookingTime = r.CookingTimeInMinutes, Ingredients = r.Ingredients, Instructions = r.Instructions }; db.Recipes.Add(toAdd); db.SaveChanges(); return toAdd.ID; } }