Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 6
0
 public int GetNumberOfRecipes()
 {
     using (var db = new RecipesEntities())
         return db.Recipes.Count();
 }