Exemple #1
0
        private CocktailViewModel GenerateViewModel(RECIPE recipe)
        {
            List <ALLERGEN> allergens = new List <ALLERGEN>();
            List <INGREDIENT_NUTRITIONAL_INFO> nutInfo     = new List <INGREDIENT_NUTRITIONAL_INFO>();
            List <RECIPE_INGREDIENT>           ingredients = recipe.RECIPE_INGREDIENT.ToList();

            foreach (RECIPE_INGREDIENT item in ingredients)
            {
                var ingAllergen = item.INGREDIENT.INGREDIENT_ALLERGEN;
                foreach (var ing in ingAllergen.Where(i => i.Present == true))
                {
                    allergens.Add(ing.ALLERGEN);
                }
                nutInfo.AddRange(item.INGREDIENT.INGREDIENT_NUTRITIONAL_INFO);
            }

            NutritionLabel label = new NutritionLabel(nutInfo);

            //TODO: Gather together the nutinfos and add them up rather than having duplicates
            CocktailViewModel model = new CocktailViewModel()
            {
                Recipe         = recipe,
                Allergens      = allergens.Distinct().ToList(),
                NutritionLabel = label
            };

            return(model);
        }
        private CocktailViewModel GenerateViewModel(RECIPE recipe)
        {
            List<ALLERGEN> allergens = new List<ALLERGEN>();
            List<INGREDIENT_NUTRITIONAL_INFO> nutInfo = new List<INGREDIENT_NUTRITIONAL_INFO>();
            List<RECIPE_INGREDIENT> ingredients = recipe.RECIPE_INGREDIENT.ToList();

            foreach (RECIPE_INGREDIENT item in ingredients) {
                var ingAllergen = item.INGREDIENT.INGREDIENT_ALLERGEN;
                foreach (var ing in ingAllergen.Where(i => i.Present == true)) {
                    allergens.Add(ing.ALLERGEN);
                }
                nutInfo.AddRange(item.INGREDIENT.INGREDIENT_NUTRITIONAL_INFO);
            }

            NutritionLabel label = new NutritionLabel(nutInfo);

            //TODO: Gather together the nutinfos and add them up rather than having duplicates
            CocktailViewModel model = new CocktailViewModel() {
                Recipe = recipe,
                Allergens = allergens.Distinct().ToList(),
                NutritionLabel = label
            };

            return model;
        }