Ejemplo n.º 1
0
        public static void ui_deleteIngredientsFromCurrentRecipe(int id, int selectedRecipe, int selectedIngredient, ref ObservableCollection <IngredientModel> ingredientList)
        {
            //int id = Convert.ToInt32(listboxIngredients.SelectedValue);

            //get the ingredient
            IngredientModel ingredientToDelete = IngredientTableDB.GetIngredient(id);

            //delete the meal link
            List <RecipeIngredLinkModel> ingred       = RecipeIngredLinkTableDB.GetIngredientsForRecipe(selectedRecipe);
            RecipeIngredLinkModel        linkToDelete = ingred.Find(x => x.IngredientId.Equals(id));

            RecipeIngredLinkTableDB.RemoveIngredientFromRecipe(linkToDelete);

            //delete the ingredient
            IngredientTableDB.RemoveIngredient(ingredientToDelete);

            //remove the deleted ingredient from the listbox
            ingredientList.RemoveAt(selectedIngredient);
        }
Ejemplo n.º 2
0
        //fully deletes the selected recipe from both the meal collection as well as the database
        //also deletes all ingredients that the recipe had as well as the links
        public static void ui_deleteRecipeFromEverything(RecipeModel recipeToDelete, ref ObservableCollection <RecipeModel> mealList)
        {
            List <RecipeIngredLinkModel> ingredientsAndLinksToDelete = RecipeIngredLinkTableDB.GetIngredientsForRecipe(recipeToDelete.Id);

            Database.RecipeTableDB.RemoveRecipe(recipeToDelete);
            mealList.Remove(recipeToDelete);

            //delete the ingredients
            foreach (RecipeIngredLinkModel ingred in ingredientsAndLinksToDelete)
            {
                IngredientTableDB.RemoveIngredient(IngredientTableDB.GetIngredient(ingred.IngredientId));
            }

            //delete the link recipeingredlink table
            foreach (RecipeIngredLinkModel link in ingredientsAndLinksToDelete)
            {
                RecipeIngredLinkTableDB.RemoveIngredientFromRecipe(link);
            }
        }