Skip to content

Commit

Permalink
Fix pagination for banned users in the mod panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Slendy committed Jul 6, 2024
1 parent e060f55 commit 2852a23
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ public BannedUsersPage(DatabaseContext database) : base(database)

public int UserCount;

public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
{
WebTokenEntity? token = this.Database.WebTokenFromRequest(this.Request);
if (token == null) return this.Redirect("/login");

this.Users = await this.Database.Users
.Where(u => u.PermissionLevel < 0)
this.UserCount = await this.Database.Users.CountAsync(u => u.PermissionLevel < 0);

this.PageNumber = pageNumber;
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));

if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
return this.Redirect($"/moderation/bannedUsers/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");

this.Users = await this.Database.Users.Where(u => u.PermissionLevel < 0)
.OrderByDescending(u => u.UserId)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)
.ToListAsync();

this.UserCount = await this.Database.Users.CountAsync(u => u.PermissionLevel < 0);

this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));

return this.Page();
}
}

0 comments on commit 2852a23

Please sign in to comment.