public ActionResult <IEnumerable <RecipeDTO> > GetRecipes() { var recipeIngredients = _context.RecipeIngredients.Include(r => r.Ingredient).ToList(); var result = _context.Recipes.Include(r => r.Ingredients).ToList(); return(result.Select(x => RecipeConverter.RecipeToRecipeDTO(x)).ToList()); }
public async Task <ActionResult <RecipeDTO> > GetRecipe(int id) { var recipe = await _context.Recipes.FindAsync(id); recipe.Ingredients = _context.RecipeIngredients.Include(r => r.Ingredient).ToList().Where(x => x.RecipeId == id).ToList(); var recipeDTO = RecipeConverter.RecipeToRecipeDTO(recipe); if (recipe == null) { return(NotFound()); } return(recipeDTO); }