Example #1
0
 public int AddRecipe(RecipeDetailsModel r, string owner)
 {
     using (var db = new RecipesEntities())
     {
         var toAdd = new Recipes
         {
             Name = r.Name,
             Summary = r.Summary,
             CookingTime = r.CookingTimeInMinutes,
             Ingredients = r.Ingredients,
             Instructions = r.Instructions,
             Owner = owner
         };
         db.Recipes.Add(toAdd);
         db.SaveChanges();
         return toAdd.ID;
     }
 }
Example #2
0
 public void UpdateRecipe(int id, RecipeDetailsModel updated, string editor)
 {
     using (var db = new RecipesEntities())
     {
         var dbRecipe = db.Recipes.FirstOrDefault(r => r.ID == id && r.Owner == editor);
         if (dbRecipe == null)
             return;
         dbRecipe.Name = updated.Name;
         dbRecipe.Summary = updated.Summary;
         dbRecipe.CookingTime = updated.CookingTimeInMinutes;
         dbRecipe.Ingredients = updated.Ingredients;
         dbRecipe.Instructions = updated.Instructions;
         db.SaveChanges();
     }
 }