public ICollection <Country> GetAllCountries() { using (var context = new RecipesContext()) { return(context.Countries.ToList()); } }
public ICollection <Chef> GetAllChefs() { using (var context = new RecipesContext()) { return(context.Chefs.ToList()); } }
public ICollection <Recipe> GetAllRecipes() { using (var context = new RecipesContext()) { return(context.Recipes.Include(x => x.Ingredients).ToList()); } }
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()); } }
public void CreateCountry(string name) { using (var context = new RecipesContext()) { Country country = new Country() { Name = name }; context.Countries.Add(country); context.SaveChanges(); } }
public void CreateChef(string name) { Chef chef = new Chef() { Name = name }; using (var context = new RecipesContext()) { context.Chefs.Add(chef); context.SaveChanges(); } }
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 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 } }