Beispiel #1
0
 public ICollection <Country> GetAllCountries()
 {
     using (var context = new RecipesContext())
     {
         return(context.Countries.ToList());
     }
 }
Beispiel #2
0
 public ICollection <Chef> GetAllChefs()
 {
     using (var context = new RecipesContext())
     {
         return(context.Chefs.ToList());
     }
 }
Beispiel #3
0
 public ICollection <Recipe> GetAllRecipes()
 {
     using (var context = new RecipesContext())
     {
         return(context.Recipes.Include(x => x.Ingredients).ToList());
     }
 }
Beispiel #4
0
 public void DeleteCountry(Country country)
 {
     using (var context = new RecipesContext())
     {
         context.Countries.Attach(country);
         context.Countries.Remove(country);
         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();
     }
 }
        public ICollection <Ingredient> GetAllIngredients()
        {
            //var context = new RecipesContext();

            //return context.Ingredients.Include(x => x.Country).ToList();

            using (var context = new RecipesContext())
            {
                return(context.Ingredients.Include(x => x.Country).ToList());
            }
        }
Beispiel #7
0
 public void CreateCountry(string name)
 {
     using (var context = new RecipesContext())
     {
         Country country = new Country()
         {
             Name = name
         };
         context.Countries.Add(country);
         context.SaveChanges();
     }
 }
Beispiel #8
0
        public void CreateChef(string name)
        {
            Chef chef = new Chef()
            {
                Name = name
            };

            using (var context = new RecipesContext())
            {
                context.Chefs.Add(chef);
                context.SaveChanges();
            }
        }
Beispiel #9
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();
            }
        }
Beispiel #10
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
            }
        }