Esempio n. 1
0
        public async Task <Double> GetCostById(Guid id)
        {
            double cost = 0;
            IEnumerable <PairItem> pairs = await _fridgeRepository.GetByRecipe(id);

            foreach (PairItem pair in pairs)
            {
                var ingredient = await _ingredientsRepository.FindById(pair.IngredientId);

                cost += ingredient.Cost * pair.Quantity;
            }
            return(cost);
        }
Esempio n. 2
0
        public async Task <IActionResult> Details(Guid id)
        {
            RecipeDTO recipeDto = new RecipeDTO();

            var recipe = await _recipesRepository.FindById(id);

            recipeDto.Content         = recipe.Content;
            recipeDto.Name            = recipe.Name;
            recipeDto.PreparationTime = recipe.PreparationTime;
            recipeDto.Servings        = recipe.NrPeopleQuantity;

            // Get the ingredients
            List <IngredientRecipeDTO> ingredientList = new List <IngredientRecipeDTO>();
            var fridgeList = await _fridgeRepository.GetByRecipe(id);

            foreach (var pairItem in fridgeList)
            {
                IngredientRecipeDTO ingredientDto = new IngredientRecipeDTO();
                var ingredientInfo = await _ingredientsRepository.FindById(pairItem.IngredientId);

                ingredientDto.Name            = ingredientInfo.Name;
                ingredientDto.MeasurementUnit = ingredientInfo.MeasuredUnit;
                ingredientDto.Quantity        = pairItem.Quantity;
                ingredientDto.Cost            = ingredientInfo.Cost;

                ingredientList.Add(ingredientDto);
            }

            recipeDto.Ingredients = ingredientList;
            return(View(recipeDto));
        }
        public async Task <IActionResult> GetAllByRecipe(Guid recipeId)
        {
            IEnumerable <PairItem> p = await _fridgeRepository.GetByRecipe(recipeId);

            List <Ingredient> ingredients = new List <Ingredient>();

            foreach (var item in p)
            {
                ingredients.Add(await _ingredientsRepository.FindById(item.IngredientId));
            }
            return(Ok(ingredients));
        }