Exemplo n.º 1
0
 public ActionResult Create()
 {
     CocktailViewModel model = new CocktailViewModel();
     model.SelectedIngredients = new List<int?>();
     model.RecipeSteps = new List<string>() { null, null, null, null, null, };
     model.Ingredients = new SelectList(db.INGREDIENT, "IngredientId", "Name");
     model.Categories = new SelectList(db.RECIPE_CATEGORY, "Recipe_CategoryId", "Name");
     return View(model);
 }
Exemplo n.º 2
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;
        }