private IList <Special> GetSelectedSpecials(PostedSpecials postedSpecials) { IList <Special> selectedSpecials = new List <Special>(); var postedSpecialIds = new string[0]; if (postedSpecials == null) { postedSpecials = new PostedSpecials(); } if (postedSpecials.Ids != null && postedSpecials.Ids.Any()) { postedSpecialIds = postedSpecials.Ids; } if (postedSpecialIds.Any()) { selectedSpecials = RecipeRepository.GetAllSpecials().Where(x => postedSpecialIds.Any(s => x.Id.ToString().Equals(s))).ToList(); } return(selectedSpecials); }
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); }