public ActionResult RechercheLivreParThemePost(RechercheLivreParThemeVM rechercheLivreParThemeVM) { if (ModelState.IsValid) { List <Livre> listeLivre = livreService.ObtenirTousLesLivres().FindAll(l => l.Theme1 == rechercheLivreParThemeVM.ThemeLivreId || l.Theme2 == rechercheLivreParThemeVM.ThemeLivreId || l.Theme3 == rechercheLivreParThemeVM.ThemeLivreId); if (listeLivre.Count == 0) { return(RedirectToAction("TousLesLivres", "Livre")); } return(RedirectToAction("TousLesLivresParTheme", new { themeId = rechercheLivreParThemeVM.ThemeLivreId })); } List <SelectListItem> listeSelect = new List <SelectListItem>(); listeSelect.Add(new SelectListItem { Text = "Veuillez sélectionner un thème", Value = "0" }); foreach (Theme theme in livreService.ObtenirTousLesThemes()) { listeSelect.Add(new SelectListItem { Text = theme.Intitule, Value = theme.Id.ToString() }); } rechercheLivreParThemeVM.ListeThemesLivres = new SelectList(listeSelect, "Value", "Text"); return(View(rechercheLivreParThemeVM)); }
public ActionResult RechercheLivreParTheme() { RechercheLivreParThemeVM rechercheLivreParThemeVM = new RechercheLivreParThemeVM(); List <SelectListItem> listeSelect = new List <SelectListItem>(); listeSelect.Add(new SelectListItem { Text = "Veuillez sélectionner un thème", Value = "0" }); foreach (Theme theme in livreService.ObtenirTousLesThemes()) { listeSelect.Add(new SelectListItem { Text = theme.Intitule, Value = theme.Id.ToString() }); } rechercheLivreParThemeVM.ListeThemesLivres = new SelectList(listeSelect, "Value", "Text"); return(View(rechercheLivreParThemeVM)); }