diff --git a/ProjectLighthouse/Helpers/StatisticsHelper.cs b/ProjectLighthouse/Helpers/StatisticsHelper.cs index c460c547..a4c6b001 100644 --- a/ProjectLighthouse/Helpers/StatisticsHelper.cs +++ b/ProjectLighthouse/Helpers/StatisticsHelper.cs @@ -12,6 +12,8 @@ public static class StatisticsHelper public static async Task SlotCount() => await database.Slots.CountAsync(); + public static async Task UserCount() => await database.Users.CountAsync(); + public static async Task MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick); public static async Task PhotoCount() => await database.Photos.CountAsync(); diff --git a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs index 5b7f4931..58056e32 100644 --- a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs +++ b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs @@ -13,6 +13,7 @@ public class BaseLayout : PageModel public readonly List NavigationItems = new() { new PageNavigationItem("Home", "/", "home"), + new PageNavigationItem("Users", "/users/0", "user friends"), new PageNavigationItem("Photos", "/photos/0", "camera"), new PageNavigationItem("Levels", "/slots/0", "certificate"), }; diff --git a/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml new file mode 100644 index 00000000..6832c030 --- /dev/null +++ b/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml @@ -0,0 +1,33 @@ +@using LBPUnion.ProjectLighthouse.Types.Settings +@model LBPUnion.ProjectLighthouse.Types.User + +@{ + bool showLink = (bool?)ViewData["ShowLink"] ?? false; +} + +
+
+ @if (showLink) + { +

+ @Model.Username +

+ } + else + { +

+ @Model.Username +

+ } +

+ @Model.Status +

+
+ @Model.Hearts + @Model.Comments + @Model.UsedSlots / @ServerSettings.Instance.EntitledSlots + @Model.PhotosByMe +
+
+ +
\ No newline at end of file diff --git a/ProjectLighthouse/Pages/UsersPage.cshtml b/ProjectLighthouse/Pages/UsersPage.cshtml new file mode 100644 index 00000000..f2d16ec2 --- /dev/null +++ b/ProjectLighthouse/Pages/UsersPage.cshtml @@ -0,0 +1,32 @@ +@page "/users/{pageNumber:int}" +@using LBPUnion.ProjectLighthouse.Types +@model LBPUnion.ProjectLighthouse.Pages.UsersPage + +@{ + Layout = "Layouts/BaseLayout"; + Model.Title = "Users"; +} + +

There are @Model.UserCount total users.

+ +@foreach (User user in Model.Users) +{ +
+ @await Html.PartialAsync("Partials/UserCardPartial", user, new ViewDataDictionary(ViewData) + { + { + "ShowLink", true + }, + }) +
+} + +@if (Model.PageNumber != 0) +{ + Previous Page +} +@(Model.PageNumber + 1) / @(Model.PageAmount) +@if (Model.PageNumber < Model.PageAmount - 1) +{ + Next Page +} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/UsersPage.cshtml.cs b/ProjectLighthouse/Pages/UsersPage.cshtml.cs new file mode 100644 index 00000000..d5535648 --- /dev/null +++ b/ProjectLighthouse/Pages/UsersPage.cshtml.cs @@ -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 Users; + + public UsersPage([NotNull] Database database) : base(database) + {} + + public async Task 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(); + } +} \ No newline at end of file