Fix pagination for banned users in the mod panel

This commit is contained in:
Slendy 2024-07-06 13:00:39 -05:00
commit 2852a23535
No known key found for this signature in database
GPG key ID: 7288D68361B91428

View file

@ -21,21 +21,25 @@ public class BannedUsersPage : BaseLayout
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();
}
}