From 2852a23535fd474bae9ac6e6c2ae26a14d48d4d2 Mon Sep 17 00:00:00 2001 From: Slendy Date: Sat, 6 Jul 2024 13:00:39 -0500 Subject: [PATCH] Fix pagination for banned users in the mod panel --- .../Pages/Moderation/BannedUsersPage.cshtml.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/BannedUsersPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Moderation/BannedUsersPage.cshtml.cs index 7376adbce..feb5b9830 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/BannedUsersPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/BannedUsersPage.cshtml.cs @@ -21,21 +21,25 @@ public BannedUsersPage(DatabaseContext database) : base(database) public int UserCount; - public async Task OnGet([FromRoute] int pageNumber, [FromQuery] string? name) + public async Task 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(); } } \ No newline at end of file