public IActionResult Index(string searchOption = null, string searchString = null, int page = 1) { if (String.IsNullOrEmpty(searchString)) { return(RedirectToAction("Index", "Home")); } var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; List <ItemUser> joinList = _db.ItemUser.Where(join => join.UserId == userId).Include(join => join.Item).ToList(); List <long> userApiIds = new List <long>(); foreach (ItemUser join in joinList) { userApiIds.Add(join.Item.ApiId); } ItemIndexViewModel model = new ItemIndexViewModel(); model.ApiIds = userApiIds; model.CurrentPage = page; model.SearchOption = searchOption; model.SearchString = searchString; if (searchOption == "games") { RawgSearchRoot results = Rawg.GetGamesSearch(searchString, page); model.GamesSearch = results; model.Results = results.Count; model.Pages = (results.Count + 19) / 20; } else if (searchOption == "movies") { TmdbMovieSearchRoot results = Tmdb.GetMoviesSearch(searchString, page); model.MovieSearch = results; model.Results = results.TotalResults; model.Pages = results.TotalPages; } else if (searchOption == "tv") { TmdbTvSearchRoot results = Tmdb.GetTvSearch(searchString, page); model.TvSearch = results; model.Results = results.TotalResults; model.Pages = results.TotalPages; } return(View(model)); }