private void cbCategories_Loaded(object sender, RoutedEventArgs e) { using (var db = new RecipesModel()) { var allCategories = db.Categories.ToList(); foreach (var category in allCategories) { cbCategories.Items.Add(category.DisplayName); } } cbCategories.Items.Add("Összes"); cbCategories.SelectedItem = "Összes"; cbCategories.IsEnabled = true; }
private void cbCategories_SelectionChanged(object sender, SelectionChangedEventArgs e) { using(var db = new RecipesModel()) { if(!((string)cbCategories.SelectedItem).Equals("Összes")) { var allRecipesInCategory = db.Recipes.Where(r => r.Categories.DisplayName == (string)cbCategories.SelectedItem).ToList(); fillListView(allRecipesInCategory); } else { lwRecipes.RaiseEvent(new RoutedEventArgs(ListView.LoadedEvent)); } } }
private void tbSearch_KeyDown(object sender, KeyEventArgs e) { if(e.Key == Key.Enter) { using (var db = new RecipesModel()) { List<Recipes> searchedRecipes = null; if (tbSearch.Text.Length > 0 && !((string)cbCategories.SelectedItem).Equals("Összes")) { searchedRecipes = db.Recipes.Where(r => r.Categories.DisplayName.Equals((string)cbCategories.SelectedItem) && r.Title.Contains(tbSearch.Text)).ToList(); } else if(tbSearch.Text.Length > 0) { searchedRecipes = db.Recipes.Where(r => r.Title.Contains(tbSearch.Text)).ToList(); } else { searchedRecipes = db.Recipes.ToList(); } fillListView(searchedRecipes); } } }
private void lwRecipes_Loaded(object sender, RoutedEventArgs e) { using (var db = new RecipesModel()) { var allRecipes = db.Recipes.ToList(); fillListView(allRecipes); } tbSearch.IsEnabled = true; lwRecipes.IsEnabled = true; }