Ejemplo n.º 1
0
        /******************************************************************/
        /*          RETREIVE FROM DATABASE AND                            */
        /******************************************************************/

        private List <recipe> PopulateViewRecipe()
        {
            var           context    = new RecipeContext();
            List <recipe> allRecipes =
                (from r in context.recipe
                 select r).ToList();

            return(allRecipes);
        }
Ejemplo n.º 2
0
        public static List <recipe> GetAllRecipes()
        {
            RecipeContext context = new RecipeContext();

            List <recipe> allRecipes = (from r in context.recipe
                                        orderby r.recipeTitle ascending
                                        select r).ToList();

            return(allRecipes);
        }
Ejemplo n.º 3
0
        public static void Delete(recipe r)
        {
            var context = new RecipeContext();

            context.recipe.Add(r);

            //mark the recipe as deleted
            context.Entry(r).State = EntityState.Deleted;

            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public static void InsertRecipe(recipe r)
        {
            RecipeContext context = new RecipeContext();

            //assume Recipe is valid
            context.recipe.Add(r);

            context.Entry(r).State = EntityState.Added;

            context.SaveChanges();
        }
Ejemplo n.º 5
0
        public static void Update(recipe r)
        {
            var context = new RecipeContext();

            //add recipe to object to current context
            context.recipe.Add(r);

            //Let EF know the book already exists
            context.Entry(r).State = EntityState.Modified;

            context.SaveChanges();
        }
Ejemplo n.º 6
0
        private void PopulateDeleteRecipe(int id)
        {
            var context = new RecipeContext();

            //pull recipe from DB to make EF track it
            recipe recipeToDelete = context.recipe.Find(id);

            //mark recipe as deleted
            context.recipe.Remove(recipeToDelete);

            //send delete query to DB
            context.SaveChanges();
        }