예제 #1
0
        public async Task <IEnumerable <Recipe> > GetByBrands(List <Product> products, Task <IEnumerable <Recipe> > recipes)
        {
            IEnumerable <Recipe> recipesWithIngredients = Enumerable.Empty <Recipe>();

            foreach (Recipe recipe in await recipes)
            {
                bool containsIngredient = false;
                IEnumerable <Ingredient> ingredients = await _ingredientsRepository.GetByRecipe(recipe.Id);

                foreach (Ingredient ingredient in ingredients)
                {
                    ProductStore productStore = await _productStoresRepository.GetById(ingredient.ProductStoreId);

                    foreach (Product product in products)
                    {
                        if (product.Id == productStore.ProductId)
                        {
                            containsIngredient = true;
                            continue;
                        }
                    }
                }

                if (containsIngredient)
                {
                    recipesWithIngredients.Append(recipe);
                }
            }


            return(recipesWithIngredients);
        }
        public async Task <IActionResult> RecipeDetails(Guid id)
        {
            RecipeDTO recipeDto = new RecipeDTO();

            Recipe recipe = await _recipesRepository.GetById(id);

            await _recipesRepository.UpdateRecipeCost(id);

            recipeDto.Name        = recipe.Name;
            recipeDto.Description = recipe.Description;
            recipeDto.Cost        = recipe.Cost;
            recipeDto.Calories    = recipe.Calories;
            recipeDto.CookingTime = recipe.CookingTime;
            recipeDto.Likes       = recipe.Likes;
            recipeDto.Rating      = recipe.Rating;
            recipeDto.Votes       = recipe.Votes;
            recipeDto.Servings    = recipe.Servings;

            List <InstructionStepDTO> instructionStepsDTOs = new List <InstructionStepDTO>();
            IEnumerable <Instruction> instructions         = await _instructionsRepository.GetByRecipe(id);

            foreach (var instruction in instructions)
            {
                InstructionStepDTO instructionStepDTO = new InstructionStepDTO
                {
                    Description   = instruction.Description,
                    InstructionNr = instruction.InstructionNr
                };
                instructionStepsDTOs.Add(instructionStepDTO);
            }

            List <IngredientDTO>     ingredientDTOs = new List <IngredientDTO>();
            IEnumerable <Ingredient> ingredients    = await _ingredientsRepository.GetByRecipe(id);

            foreach (var ingredient in ingredients)
            {
                IngredientDTO ingredientDTO = new IngredientDTO
                {
                    Name                  = ingredient.Name,
                    Cost                  = ingredient.Cost,
                    Quantity              = ingredient.Quantity,
                    UnitOfMeasurement     = ingredient.UnitOfMeasurement,
                    NrOfProductsNecessary = ingredient.NrOfProductsNecessary
                };

                ingredientDTOs.Add(ingredientDTO);
            }

            recipeDto.Ingredients      = ingredientDTOs;
            recipeDto.InstructionSteps = instructionStepsDTOs;


            return(Ok(recipeDto));
        }