コード例 #1
0
        private RecipeModel GetModel()
        {
            var model         = new RecipeModel();
            var allCategories = RecipeRepository.GetAllCategories();
            var allDishTypes  = RecipeRepository.GetAllDishTypes();
            var allSpecials   = RecipeRepository.GetAllSpecials();

            var categoryItems = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "--- Välj ---", Value = "0"
                }
            };
            var dishTypeItems = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "--- Välj ---", Value = "0"
                }
            };
            var portionItems = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "--- Välj ---", Value = "0"
                },
                new SelectListItem {
                    Text = "1", Value = "1"
                },
                new SelectListItem {
                    Text = "2", Value = "2"
                },
                new SelectListItem {
                    Text = "3", Value = "3"
                },
                new SelectListItem {
                    Text = "4", Value = "4"
                },
                new SelectListItem {
                    Text = "5", Value = "5"
                },
                new SelectListItem {
                    Text = "6", Value = "6"
                },
                new SelectListItem {
                    Text = "7", Value = "7"
                },
                new SelectListItem {
                    Text = "8", Value = "8"
                },
            };

            categoryItems.AddRange(allCategories.Select(category => new SelectListItem {
                Text = category.Name, Value = category.Id.ToString()
            }));
            dishTypeItems.AddRange(allDishTypes.Select(dishType => new SelectListItem {
                Text = dishType.Name, Value = dishType.Id.ToString()
            }));

            model.Recipe        = new Recipe();
            model.AllCategories = categoryItems;
            model.AllDishTypes  = dishTypeItems;
            model.Portions      = portionItems;
            model.AllSpecials   = allSpecials;
            return(model);
        }