Beispiel #1
0
        public void CreateRecipe(Recipe recipe)
        {
            using (var context = new RecipesContext())
            {
                context.Recipes.Add(recipe);

                foreach (var ingredient in recipe.Ingredients)
                {
                    context.Entry(ingredient).State = EntityState.Unchanged;
                }

                context.Entry(recipe.Chef).State = EntityState.Unchanged;

                context.SaveChanges();
            }
        }
 public void CreateIngredient(Ingredient ingredient)
 {
     using (var context = new RecipesContext())
     {
         context.Ingredients.Add(ingredient);
         context.Entry(ingredient.Country).State = System.Data.Entity.EntityState.Unchanged;
         context.SaveChanges();
     }
 }
Beispiel #3
0
        public void UpdateCountry(Country country)
        {
            //using (var context = new RecipesContext())
            //{
            //    context.Countries.Attach(country);
            //    country.Name = newName;
            //    var state = context.Entry(country).State;
            //    context.SaveChanges();
            //}


            using (var context = new RecipesContext())
            {
                context.Countries.Attach(country);                   // bo mira que el country esta en la base (POR DEFECTO VA COMO UNCHANGED)
                context.Entry(country).State = EntityState.Modified; // este va como modified, actualizalo
                context.SaveChanges();                               // confirma los cambios
            }
        }