private void populateLists(RevCookBookContext context) { //var categoriesList = new List<SelectListItem>(); var selectedCategoriesIds = new List <int>(); if (Categories != null) { foreach (var category in Categories) { selectedCategoriesIds.Add(category.CategoryId); } } CategoriesList = new MultiSelectList(context.Categories, "CategoryId", "Name", selectedCategoriesIds); SelectedCategories = context.Categories .Where(category => selectedCategoriesIds.FindIndex(id => id == category.CategoryId) != -1) .ToList(); //foreach (var category in context.Categories) //{ // SelectListItem selectListItem = new SelectListItem() // { // Text = category.Name, // Value = category.CategoryId.ToString(), // Selected = selectedCategoriesIds.FindIndex(id => id == category.CategoryId) != -1 // }; // categoriesList.Add(selectListItem); //} //CategoriesList = categoriesList; }
public IngredientViewModel(RevCookBookContext context, Ingredient ingredient = null) { if (ingredient != null) { IngredientId = ingredient.IngredientId; Name = ingredient.Name; Categories = ingredient.Categories; } populateLists(context); }
public RecipeViewModel(RevCookBookContext context, Recipe recipe) { Recipe = recipe; RecipeId = recipe.RecipeId; LanguageId = recipe.LanguageId; DishId = recipe.DishId; Text = recipe.Text; Dish = recipe.Dish; Language = recipe.Language; populateLists(context, recipe.DishId, recipe.LanguageId); }
private void populateLists(RevCookBookContext context, object SelectedDishId = null, object SelectedLanguageId = null) { var dishesQuery = from dishes in context.Dishes orderby dishes.Name select dishes; var languagesQuery = from languages in context.Languages orderby languages.LanguageId select languages; DishesList = new SelectList(dishesQuery, "DishId", "Name", SelectedDishId); LanguagesList = new SelectList(languagesQuery, "LanguageId", "LanguageCode", SelectedDishId); }
public RecipeViewModel(RevCookBookContext context) { populateLists(context); }
public IngredientCategoriesController(RevCookBookContext context) { _context = context; }
public CategoriesController(RevCookBookContext context) { _context = context; }
public LanguagesController(RevCookBookContext context) { _context = context; }
public RecipesController(RevCookBookContext context) { _context = context; }
public DishesController(RevCookBookContext context) { _context = context; }