public void DeleteRecipe(int x) { using (RecipesContext context = new RecipesContext()) { Recipe r = (from Recipe recipe in context.Recipes where recipe.RecipeID == x select recipe).FirstOrDefault(); context.Recipes.Remove(r); context.SaveChanges(); } }
public void AddNewRecipe(Recipe r) { try { using (RecipesContext context = new RecipesContext()) { context.Recipes.Add(r); context.SaveChanges(); } } catch (Exception e) { throw e; } }
public void RefreshData() { using (RecipesContext context = new RecipesContext()) { List <Recipe> rawRecipes = (from Recipe r in context.Recipes select r).ToList(); Recipes = new List <Recipe>(); foreach (Recipe r in rawRecipes) { Recipe newRecipe = CreateRecipe(r); Recipes.Add(newRecipe); } Ingredients = (from Ingredient i in context.Ingredients select i).ToList(); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { using (RecipesContext context = new RecipesContext()) { List <Recipe> recipes = (from Recipe r in context.Recipes select r).ToList(); XMLSerializer.XMLRecipeSerializer(recipes, RecipesXMLLocation); List <Ingredient> ingredients = (from Ingredient i in context.Ingredients select i).ToList(); XMLSerializer.XMLIngredientSerializer(ingredients, IngredientsXMLLocation); } } Recipes = null; Ingredients = null; disposedValue = true; } }