예제 #1
0
 public ICollection <Country> GetAllCountries()
 {
     using (var context = new RecipesContext())
     {
         return(context.Countries.ToList());
     }
 }
예제 #2
0
 public ICollection <Chef> GetAllChefs()
 {
     using (var context = new RecipesContext())
     {
         return(context.Chefs.ToList());
     }
 }
예제 #3
0
 public ICollection <Recipe> GetAllRecipes()
 {
     using (var context = new RecipesContext())
     {
         return(context.Recipes.Include(x => x.Ingredients).ToList());
     }
 }
예제 #4
0
 public void DeleteCountry(Country country)
 {
     using (var context = new RecipesContext())
     {
         context.Countries.Attach(country);
         context.Countries.Remove(country);
         context.SaveChanges();
     }
 }
예제 #5
0
 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();
     }
 }
예제 #6
0
        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());
            }
        }
예제 #7
0
 public void CreateCountry(string name)
 {
     using (var context = new RecipesContext())
     {
         Country country = new Country()
         {
             Name = name
         };
         context.Countries.Add(country);
         context.SaveChanges();
     }
 }
예제 #8
0
        public void CreateChef(string name)
        {
            Chef chef = new Chef()
            {
                Name = name
            };

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