public static List <SearchGame> GetSearchGamesForUser(this ApplicationDbContext _context, string UserID) { IEnumerable <GameAccess> accesses = _context.GetGameAccessForUser(UserID); return((SearchGame.GenerateMany(_context, accesses.Select(g => g.game.ID).ToArray())).ToList()); }
public async Task <IActionResult> Index(string q = null, byte?searchLimit = 20, int?pageNumber = 0) { bool loggedIn = User.IsLoggedIn(); ViewData["LoggedIn"] = (bool?)loggedIn; if (loggedIn) { ViewData["MyGames"] = (await _context.GetSearchGamesForUserAsync(User.GetUserId())); } else { ViewData["MyGames"] = null; } ViewData["query"] = q; List <SearchGame> ret; if (!String.IsNullOrWhiteSpace(q)) { List <int> results = (await _context.SearchGames(q)); ret = (SearchGame.GenerateMany(_context, results.ToArray())).ToList(); } else { Game[] results = (await _context.Games .Include(g => g.Accesses) .OrderBy(g => g.Accesses.Count) .Skip(pageNumber.Value * searchLimit.Value) .Take(searchLimit.Value) .ToArrayAsync()); ret = (SearchGame.GenerateMany(_context, results)).ToList(); } return(View(ret)); }