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 List<RecipeSummaryModel> GetAllRecipes()
 {
     using (var db = new RecipesEntities())
     {
         return (from r in db.Recipes
                 select new RecipeSummaryModel
                 {
                     ID = r.ID,
                     Name = r.Name,
                     Summary = r.Summary
                 }).ToList();
     }
 }
 public RecipeSummaryModel GetRandomRecipe()
 {
     using (var db = new RecipesEntities())
     {
         return (from r in db.Recipes
                 orderby Guid.NewGuid()
                 select new RecipeSummaryModel
                 {
                     ID = r.ID,
                     Name = r.Name,
                     Summary = r.Summary
                 }).First();
     }
 }
 public RecipeDetailsModel GetRecipe(int id)
 {
     using (var db = new RecipesEntities())
     {
         return (from r in db.Recipes
                 where r.ID == id
                 select new RecipeDetailsModel
                 {
                     Name = r.Name,
                     Summary = r.Summary,
                     CookingTimeInMinutes = r.CookingTime,
                     Ingredients = r.Ingredients,
                     Instructions = r.Instructions
                 }).FirstOrDefault();
     }
 }
 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;
     }
 }
 public List<RecipeSummaryModel> SearchFor(string Term)
 {
     using (var db = new RecipesEntities())
     {
         return (from r in db.Recipes
                 where r.Name.ToLower().Contains(Term.ToLower())
                 select new RecipeSummaryModel
                 {
                     ID = r.ID,
                     Name = r.Name,
                     Summary = r.Summary
                 }).ToList();
     }
 }
 public int GetNumberOfRecipes()
 {
     using (var db = new RecipesEntities())
         return db.Recipes.Count();
 }