예제 #1
0
 public ActionResult Edit(int id, RecipeDetailsModel updated)
 {
     if (ModelState.IsValid)
     {
         ro.UpdateRecipe(id, updated);
         return RedirectToAction("FullDetails", new { id = id });
     }
     else
     {
         return View(updated);
     }
 }
예제 #2
0
 public ActionResult Submit(RecipeDetailsModel r)
 {
     if (ModelState.IsValid)
     {
         var id = ro.AddRecipe(r);
         return RedirectToAction("FullDetails", new { id = id });
     }
     else
     {
         return View(r);
     }
 }
예제 #3
0
 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();
     }
 }
예제 #4
0
 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;
     }
 }