Beispiel #1
0
        public bool UpdateRecipe(RecipeView recipe)
        {
            var updatedRecipe = GetRecipeById(recipe.Id);

            if (updatedRecipe != null)
            {
                updatedRecipe.Name        = recipe.Name;
                updatedRecipe.Description = recipe.Description;
                updatedRecipe.RecipeTags.RemoveAll(r => r.RecipeId == recipe.Id);
                SaveChanges();
                //update tags at some point
                foreach (string t in recipe.Tags)
                {
                    var result = _tags.FindTag(t);
                    if (result == null)
                    {
                        result = _tags.AddTag(t);
                    }
                    //add the 'join' between recipe and tag
                    _recipe.Add(new RecipeTag {
                        RecipeId = recipe.Id, TagId = result.Id
                    });
                }
                _recipe.Recipes.Update(updatedRecipe);
                SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }