public List <Recipe> GetAllRecipesWithIngredients() { List <Recipe> recipes = GetAllRecipes(); IngredientRepository ir = new IngredientRepository(); List <Ingredient> ingredients = ir.GetAllIngredientsFull(); recipes.ForEach(r => r.Ingredients.AddRange(ingredients.Where(i => i.RecipeId == r.Id))); return(recipes); }
public Recipe GetRecipe(int id) { IngredientRepository ir = new IngredientRepository(); List <Ingredient> ingredients = ir.GetAllIngredientsFull(); DataTable dt = ExecuteQuery($"select * from Recipes where Id = {id};"); if (dt.Rows.Count == 0) { return(null); } return(new Recipe { Id = (int)dt.Rows[0]["Id"], Name = (string)dt.Rows[0]["Name"], Description = (string)dt.Rows[0]["Description"], Ingredients = ingredients.Where(i => i.RecipeId == (int)dt.Rows[0]["Id"]).ToList() }); }