Add users page

This commit is contained in:
jvyden 2022-01-19 08:29:17 -05:00
parent 7cc3a613e7
commit b4440659a6
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
5 changed files with 113 additions and 0 deletions

View 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();
}
}