예제 #1
0
        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());
        }
예제 #2
0
        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);
        }