Esempio n. 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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();
     }
 }
Esempio n. 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;
     }
 }