mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-25 10:49:01 +00:00
Show users currently online on front page
This commit is contained in:
parent
9b73a94b65
commit
8facca8b39
2 changed files with 24 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
|||
@page "/"
|
||||
@using LBPUnion.ProjectLighthouse.Types
|
||||
@model LBPUnion.ProjectLighthouse.Pages.LandingPage
|
||||
|
||||
@{
|
||||
|
@ -11,15 +12,23 @@
|
|||
<p>You are currently logged in as <b>@Model.User.Username</b>.</p>
|
||||
}
|
||||
|
||||
@if (Model.PlayersOnline == 1)
|
||||
@if (Model.PlayersOnlineCount == 1)
|
||||
{
|
||||
<p>There is 1 user currently online.</p>
|
||||
<p>There is 1 user currently online:</p>
|
||||
@foreach (User user in Model.PlayersOnline)
|
||||
{
|
||||
<a href="/user/@user.UserId">@user.Username</a>
|
||||
}
|
||||
}
|
||||
else if (Model.PlayersOnline == 0)
|
||||
else if (Model.PlayersOnlineCount == 0)
|
||||
{
|
||||
<p>There are no users online. Why not hop on?</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>There are currently @Model.PlayersOnline users online.</p>
|
||||
<p>There are currently @Model.PlayersOnlineCount users online:</p>
|
||||
@foreach (User user in Model.PlayersOnline)
|
||||
{
|
||||
<a href="/user/@user.UserId">@user.Username</a>
|
||||
}
|
||||
}
|
|
@ -1,9 +1,13 @@
|
|||
#nullable enable
|
||||
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 Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Pages
|
||||
{
|
||||
|
@ -12,12 +16,17 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
|||
public LandingPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public int PlayersOnline;
|
||||
public int PlayersOnlineCount;
|
||||
public List<User> PlayersOnline;
|
||||
|
||||
[UsedImplicitly]
|
||||
public async Task<IActionResult> OnGet()
|
||||
{
|
||||
this.PlayersOnline = await StatisticsHelper.RecentMatches();
|
||||
this.PlayersOnlineCount = await StatisticsHelper.RecentMatches();
|
||||
|
||||
List<int> userIds = await this.Database.LastMatches.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync();
|
||||
|
||||
this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync();
|
||||
return this.Page();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue