Esempio n. 1
0
        private void OnSaveChanges()
        {
            List <RecipeProduct> recipeProductsToRemove = new List <RecipeProduct>();
            List <RecipeProduct> recipeProductsToAdd    = new List <RecipeProduct>();

            //remove products that were present only before changes
            UnchangedSelectedRecipe.RecipeProducts.ForEach(rp =>
            {
                if (!SelectedRecipe.RecipeProducts.Where(rp2 => rp2.Id == rp.Id).Any())
                {
                    recipeProductsToRemove.Add(rp);
                }
            });
            //add products that weren't present before
            SelectedRecipe.RecipeProducts.ForEach(rp =>
            {
                if (!UnchangedSelectedRecipe.RecipeProducts.Where(rp2 => rp2.Id == rp.Id).Any())
                {
                    recipeProductsToAdd.Add(rp);
                }
            });

            recipeProductsToAdd.ForEach(rp => _recipesRepository.AddRecipeProduct(rp));
            recipeProductsToRemove.ForEach(rp => _recipesRepository.RemoveRecipeProduct(rp));
            //_recipesRepository.UpdateRecipe(SelectedRecipe);
            _recipesRepository.Save();
            EditMode = false;
        }
Esempio n. 2
0
        private void OnSaveChanges()
        {
            List <RecipeProduct> recipeProductsToRemove = new List <RecipeProduct>();
            List <RecipeProduct> recipeProductsToAdd    = new List <RecipeProduct>();

            //remove products that were present only before changes
            UnchangedSelectedRecipe.RecipeProducts.ForEach(rp =>
            {
                if (!SelectedRecipe.RecipeProducts.Where(rp2 => rp2.Id == rp.Id).Any())
                {
                    recipeProductsToRemove.Add(rp);
                }
            });
            //add products that weren't present before
            SelectedRecipe.RecipeProducts.ForEach(rp =>
            {
                if (!UnchangedSelectedRecipe.RecipeProducts.Where(rp2 => rp2.Id == rp.Id).Any())
                {
                    recipeProductsToAdd.Add(rp);
                }
            });

            recipeProductsToAdd.ForEach(rp => _recipesRepository.AddRecipeProduct(rp));
            recipeProductsToRemove.ForEach(rp => _recipesRepository.RemoveRecipeProduct(rp));
            //_recipesRepository.UpdateRecipe(SelectedRecipe);
            _recipesRepository.Save();
            EditMode = false;

            ClearSelectedProductUserInput();

            _eventAggregator.GetEvent <RecipeUpdatedEvent>().Publish(
                new RecipeUpdatedEventArgs {
                UpdatedRecipe = SelectedRecipe
            }
                );
        }