示例#1
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();
     }
 }
示例#2
0
 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();
     }
 }
示例#3
0
 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();
     }
 }
示例#4
0
 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();
     }
 }
示例#5
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;
     }
 }
示例#6
0
 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();
     }
 }
示例#7
0
 public int GetNumberOfRecipes()
 {
     using (var db = new RecipesEntities())
         return db.Recipes.Count();
 }