Ejemplo n.º 1
0
        public async Task <IEnumerable <RecipeViewModel> > GetRecipes()
        {
            List <RecipeViewModel> recipes = new List <RecipeViewModel>();
            var result = await _recipeRepo.ListAllAsync();

            foreach (Recipe recipe in result)
            {
                RecipeViewModel recipeViewModel = new RecipeViewModel();
                recipeViewModel.Id              = recipe.Id;
                recipeViewModel.Name            = recipe.Name;
                recipeViewModel.NumberOfPersons = recipe.NumberOfPersons;
                var stepresult = _stepRepository.GetByRecipeId(recipe.Id);
                foreach (Step step in stepresult)
                {
                    StepViewModel localstep = new StepViewModel();
                    localstep.Id          = step.Id;
                    localstep.Description = step.Description;
                    localstep.Number      = step.Number;
                    recipeViewModel.Steps.Add(localstep);
                }

                var ingredientresult = _ingredientRepository.GetByRecipeId(recipe.Id);
                foreach (Ingredient item in ingredientresult)
                {
                    IngredientViewModel localIngredient = new IngredientViewModel();
                    localIngredient.Id   = item.Id;
                    localIngredient.Name = item.Name;
                    recipeViewModel.Ingredients.Add(localIngredient);
                }

                recipes.Add(recipeViewModel);
            }
            return(recipes);
        }