mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-19 16:02:26 +00:00
Add users page
This commit is contained in:
parent
7cc3a613e7
commit
b4440659a6
5 changed files with 113 additions and 0 deletions
45
ProjectLighthouse/Pages/UsersPage.cshtml.cs
Normal file
45
ProjectLighthouse/Pages/UsersPage.cshtml.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Pages;
|
||||
|
||||
public class UsersPage : BaseLayout
|
||||
{
|
||||
public int PageAmount;
|
||||
|
||||
public int PageNumber;
|
||||
|
||||
public int UserCount;
|
||||
|
||||
public List<User> Users;
|
||||
|
||||
public UsersPage([NotNull] Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
||||
{
|
||||
this.UserCount = await StatisticsHelper.UserCount();
|
||||
|
||||
this.PageNumber = pageNumber;
|
||||
this.PageAmount = (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize);
|
||||
|
||||
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/users/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
||||
|
||||
this.Users = await this.Database.Users.OrderByDescending
|
||||
(p => p.UserId)
|
||||
.Skip(pageNumber * ServerStatics.PageSize)
|
||||
.Take(ServerStatics.PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue