public async Task <AccountListDTO> GetAccountList(int?pageNumber, string searchKey) { var users = _accountRepository.Query().Where(x => string.IsNullOrEmpty(searchKey) || x.Name.ToLower().Contains(searchKey) || x.Email.ToLower().Contains(searchKey) || x.Players.Any(y => y.Name.ToLower().Contains(searchKey))); var currentPageNum = pageNumber ?? 1; var offset = (ServerInfo.ItemsPerPage * currentPageNum) - ServerInfo.ItemsPerPage; var model = new AccountListDTO() { TotalResults = await users.CountAsync() }; var result = await users .Skip(offset) .Take(ServerInfo.ItemsPerPage) .ToListAsync(); foreach (var account in result) { var isAccountBanned = await _banService.IsBanned(account); var isAccountLocked = await _userManager.IsLockedOutAsync(account.AccountIdentity); var AccountRole = (await _userManager.GetRolesAsync(account.AccountIdentity)).Single(); var banReason = isAccountBanned ? account.AccountBan.Reason : string.Empty; var accountListItem = new AccountListItemDTO() { Id = account.Id, AccountName = account.Name, Email = account.Email, Characters = account.Players.Select(x => x.Name), IsLocked = isAccountLocked, Role = AccountRole, IsBanned = isAccountBanned, IsBannedReason = banReason }; model.Accounts.Add(accountListItem); } return(model); }