public ActionResult OnGet() { if (!User.Identity.IsAuthenticated) { return RedirectToPage("/Account/Login", new { area = "Identity" }); } try { string cs = _config.GetConnectionString("Default"); Films = fd.GetFilmList(cs); Users = fd.GetUserList(cs); var genres = fd.GetGenreList(cs); Genre = new List<SelectListItem>(); genres.ForEach(x => { Genre.Add(new SelectListItem { Value = x.GenreID.ToString(), Text = x.GenreText }); }); RandomFilm = fd.GetRandomFilm(cs); return Page(); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public async Task <IActionResult> OnGet() { if (!User.Identity.IsAuthenticated) { return(RedirectToPage("/Account/Login", new { area = "Identity" })); } try { string cs = _config.GetConnectionString("Default"); FilmDetails = fd.GetFilmDetails(cs, Id).FirstOrDefault(); if (FilmDetails != null) { if (FilmDetails != null) { var genres = fd.GetGenreList(cs); var directors = fd.GetDirectorsList(cs); var users = fd.GetUserList(cs); //Genre = genres.Where(x => x.GenreID == FilmDetails.GenreID).FirstOrDefault()?.GenreText; Genres = new List <SelectListItem>(); Directors = new List <SelectListItem>(); Users = new List <SelectListItem>(); genres.ForEach(x => { if (FilmDetails.GenreID == x.GenreID) { Genres.Add(new SelectListItem { Value = x.GenreID.ToString(), Text = x.GenreText, Selected = true }); } else { Genres.Add(new SelectListItem { Value = x.GenreID.ToString(), Text = x.GenreText }); } }); directors.ForEach(x => { if (FilmDetails.DirectorID == x.DirectorID) { Directors.Add(new SelectListItem { Value = x.DirectorID.ToString(), Text = x.DirectorName, Selected = true }); } else { Directors.Add(new SelectListItem { Value = x.DirectorID.ToString(), Text = x.DirectorName }); } }); users.ForEach(x => { if (FilmDetails.AddedByID == x.UserID) { Users.Add(new SelectListItem { Value = x.UserID.ToString(), Text = x.UserName, Selected = true }); } else { Users.Add(new SelectListItem { Value = x.UserID.ToString(), Text = x.UserName }); } }); } } return(Page()); } catch (Exception ex) { throw new Exception(ex.ToString()); } }