public CookbookRepositoryRecipe Add(CookbookRepositoryRecipe cookbookRepositoryRecipe)
        {
            Recipe recipe = toDatabaseRecipe(cookbookRepositoryRecipe);

            DatabaseManager.Instance.Recipe.Add(recipe);
            DatabaseManager.Instance.SaveChanges();
            cookbookRepositoryRecipe.ID = recipe.Id;
            return(cookbookRepositoryRecipe);
        }
        private Recipe toDatabaseRecipe(CookbookRepositoryRecipe cookbookRepositoryRecipe)
        {
            Recipe recipe = new Recipe
            {
                Id         = cookbookRepositoryRecipe.ID,
                Title      = cookbookRepositoryRecipe.Title,
                Author     = cookbookRepositoryRecipe.Author,
                Directions = cookbookRepositoryRecipe.Directions,
                ImageUrl   = cookbookRepositoryRecipe.ImageURL,
                Ingredient = cookbookRepositoryRecipe.Ingredients.Select(ing => new Ingredient
                {
                    Name     = ing.Name,
                    Price    = ing.Price,
                    ImageUrl = ing.ImageURL
                }).ToList()
            };

            return(recipe);
        }
        public bool Remove(CookbookRepositoryRecipe cookbookRepositoryRecipe)
        {
            IQueryable <Recipe> recipes = DatabaseManager.Instance.Recipe.Where(r => r.Id == cookbookRepositoryRecipe.ID);

            if (recipes.Count() == 0)
            {
                return(false);
            }
            Recipe recipe = recipes.First();

            if (cookbookRepositoryRecipe.Ingredients.Count() > 0)
            {
                foreach (CookbookRepositoryIngredient ing in cookbookRepositoryRecipe.Ingredients)
                {
                    RemoveIngredient(ing.ID, false);
                }
                DatabaseManager.Instance.SaveChanges();
            }
            DatabaseManager.Instance.Recipe.Remove(recipes.First());
            DatabaseManager.Instance.SaveChanges();
            return(true);
        }
        public bool Update(CookbookRepositoryRecipe cookbookRepositoryRecipe)
        {
            Recipe originalRecipe = DatabaseManager.Instance.Recipe.Find(cookbookRepositoryRecipe.ID);

            if (originalRecipe != null)
            {
                DatabaseManager.Instance.Entry(originalRecipe).CurrentValues.SetValues(toDatabaseRecipe(cookbookRepositoryRecipe));
                foreach (CookbookRepositoryIngredient ing in cookbookRepositoryRecipe.Ingredients)
                {
                    if (ing.ID == 0)
                    {
                        originalRecipe.Ingredient.Add(new Ingredient
                        {
                            Name     = ing.Name,
                            Price    = ing.Price,
                            ImageUrl = ing.ImageURL
                        });
                    }
                }
                DatabaseManager.Instance.SaveChanges();
                return(true);
            }
            return(false);
        }