public IActionResult Search(SearchMovieViewModel vm) { // TODO - Show what filters have been applied. // List<Film> films = new List<Film>(); // Gets films matching the search value and filter (if selected). List <Film> films = _filmServices.GetAllCompleteFilms() .WhereIf(!string.IsNullOrEmpty(vm.MediaFilter), f => f.Media.Name == vm.MediaFilter) .WhereIf(!string.IsNullOrEmpty(vm.SearchValue), f => f.Name.ToLower().Contains(vm.SearchValue.ToLower())) .WhereIf(!string.IsNullOrEmpty(vm.AudioFilter), f => f.Audio.Name == vm.AudioFilter) .WhereIf(!string.IsNullOrEmpty(vm.GenreFilter), f => f.FilmGenres.Any(fg => fg.Genre != null && fg.Genre.Name == vm.GenreFilter)) .ToList(); // Filter out films that should not be visible to the User based on privacy level films = _filmServices.GetAllVisible(films, User); // sort the collection of films by selected value (title ascending is default) vm.Films = _filmServices.SortBy(films, vm.SortPriority); // TODO - Check if Genres needs the full Genre models or just the Ids vm.Genres = _context.Genres.ToList(); vm.MediaFormats = _context.MediaFormats.ToList(); vm.AudioFormats = _context.AudioFormats.ToList(); // TODO - Add pagination for the results. See WebSearch. return(View(vm)); }
public IActionResult DisplayUser(DisplayUserViewModel vm) { ApplicationUser user = _context.Users.SingleOrDefault(u => u.UserName == vm.UserName); // If someone attempts to access a page for a private User directly and is not that User // and is not an Admin, they are redirected to the Index Action. if (!ModelState.IsValid || (user.IsPrivate && !User.IsInRole("Admin") && user.Id != _userManager.GetUserId(User))) { return(RedirectToAction("Index")); } List <Film> films = new List <Film>(); films = _userServices.GetUserFilms(user, User).Include(f => f.FilmGenres).ThenInclude(fg => fg.Genre).ToList(); films = films .Where(f => string.IsNullOrEmpty(vm.AudioFilter) || f.Audio.Name == vm.AudioFilter) .Where(f => string.IsNullOrEmpty(vm.MediaFilter) || f.Media.Name == vm.MediaFilter) .Where(f => string.IsNullOrEmpty(vm.GenreFilter) || f.FilmGenres.Any(fg => fg.Genre.Name == vm.GenreFilter)) .Where(f => string.IsNullOrEmpty(vm.SearchValue) || f.Name.ToLower().Contains(vm.SearchValue.ToLower())) .ToList(); vm.Films = _filmServices.SortBy(films, vm.SortPriority); vm.Genres = _context.Genres.ToList(); vm.MediaFormats = _context.MediaFormats.ToList(); vm.AudioFormats = _context.AudioFormats.ToList(); if (!string.IsNullOrEmpty(user.ProfilePicture)) { vm.ProfilePicturePath = GlobalVariables.ImagesBasePath + user.UserName + "/" + user.ProfilePicture; } else { vm.ProfilePicturePath = GlobalVariables.DefaultProfilePicture; } return(View(vm)); }