Esempio n. 1
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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }