Add simple photos page

This commit is contained in:
jvyden 2021-11-22 18:58:56 -05:00
commit b137d3fc79
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 55 additions and 5 deletions

View file

@ -13,5 +13,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
public static async Task<int> MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick);
public static async Task<int> PhotoCount() => await database.Photos.CountAsync();
}
}

View file

@ -28,6 +28,7 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
public readonly List<PageNavigationItem> NavigationItems = new()
{
new PageNavigationItem("Home", "/", "home"),
new PageNavigationItem("Photos", "/photos", "camera"),
};
}

View file

@ -1,4 +1,5 @@
@page
@page "/photos"
@using LBPUnion.ProjectLighthouse.Types
@model LBPUnion.ProjectLighthouse.Pages.PhotosPage
@{
@ -6,3 +7,28 @@
}
<h1>Photos</h1>
<p>There are @Model.PhotoCount total photos!</p>
@foreach (Photo photo in Model.Photos)
{
<div class="ui segment">
<img src="/gameAssets/@photo.LargeHash" style="width: 100%; height: auto; border-radius: .28571429rem;"><br>
<p>
<i>
Taken by
<b>
<a href="/users/@photo.Creator!.UserId">@photo.Creator.Username</a>
</b>
</i>
</p>
<p>
<b>Photo contains @photo.Subjects.Count @(photo.Subjects.Count == 1 ? "person" : "people"):</b>
</p>
@foreach (PhotoSubject subject in photo.Subjects)
{
<a href="/users/@subject.UserId">@subject.User.Username</a>
}
</div>
}

View file

@ -1,10 +1,31 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
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
{
public class PhotosPage : PageModel
public class PhotosPage : BaseLayout
{
public void OnGet()
public PhotosPage([NotNull] Database database) : base(database)
{}
public int PhotoCount;
public List<Photo> Photos;
public async Task<IActionResult> OnGet()
{
this.PhotoCount = await StatisticsHelper.PhotoCount();
this.Photos = await this.Database.Photos.Include(p => p.Creator).Take(20).ToListAsync();
return this.Page();
}
}
}