コード例 #1
0
        public static void CreateNewRecipe(List <IngredientByRecipe> ingredientByRecipeList, Recipe newRecipe)
        {
            recipeId++;
            var database = new SQLiteDataService();

            database.Initialize();
            newRecipe.Id = recipeId;
            database.AddRecipe(newRecipe);
            ingredientByRecipeList.ForEach(ibr =>
            {
                ibr.RecipeId = newRecipe.Id;
                database.AddIngredientByRecipe(ibr);
            });
            database.Close();
            AllUsersRecipes.Add(new RecipeViewModel(newRecipe));
        }
コード例 #2
0
        public static void UpdateRecipe(List <IngredientByRecipe> ingredientByRecipeList, Recipe recipe, RecipeViewModel recipeView)
        {
            var originalRecipe = recipeView.GetRecipe();
            var database       = new SQLiteDataService();

            database.Initialize();
            database.UpdateRecipe(recipe);
            database.DeleteIngredientsByRecipe(originalRecipe.Id);
            ingredientByRecipeList.ForEach(ibr =>
            {
                ibr.RecipeId = originalRecipe.Id;
                database.AddIngredientByRecipe(ibr);
            });
            database.Close();
            var allUsersRecipesList = AllUsersRecipes.ToList();

            AllUsersRecipes.Clear();
            var index = allUsersRecipesList.IndexOf(recipeView);

            allUsersRecipesList.RemoveAt(index);
            allUsersRecipesList.Insert(index, new RecipeViewModel(recipe));
            allUsersRecipesList.ForEach(rVM => AllUsersRecipes.Add(rVM));
        }