diff --git a/ProjectLighthouse/Helpers/StatisticsHelper.cs b/ProjectLighthouse/Helpers/StatisticsHelper.cs index 3a43ed81..53d51710 100644 --- a/ProjectLighthouse/Helpers/StatisticsHelper.cs +++ b/ProjectLighthouse/Helpers/StatisticsHelper.cs @@ -13,5 +13,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers public static async Task SlotCount() => await database.Slots.CountAsync(); public static async Task MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick); + + public static async Task PhotoCount() => await database.Photos.CountAsync(); } } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs index 41c6daf3..7c7be87a 100644 --- a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs +++ b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml.cs @@ -28,6 +28,7 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts public readonly List NavigationItems = new() { new PageNavigationItem("Home", "/", "home"), + new PageNavigationItem("Photos", "/photos", "camera"), }; } diff --git a/ProjectLighthouse/Pages/PhotosPage.cshtml b/ProjectLighthouse/Pages/PhotosPage.cshtml index ee872eea..8caf6fb4 100644 --- a/ProjectLighthouse/Pages/PhotosPage.cshtml +++ b/ProjectLighthouse/Pages/PhotosPage.cshtml @@ -1,8 +1,34 @@ -@page +@page "/photos" +@using LBPUnion.ProjectLighthouse.Types @model LBPUnion.ProjectLighthouse.Pages.PhotosPage @{ Layout = "Layouts/BaseLayout"; } -

Photos

\ No newline at end of file +

Photos

+

There are @Model.PhotoCount total photos!

+ +@foreach (Photo photo in Model.Photos) +{ +
+
+ +

+ + Taken by + + @photo.Creator.Username + + +

+ +

+ Photo contains @photo.Subjects.Count @(photo.Subjects.Count == 1 ? "person" : "people"): +

+ @foreach (PhotoSubject subject in photo.Subjects) + { + @subject.User.Username + } +
+} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/PhotosPage.cshtml.cs b/ProjectLighthouse/Pages/PhotosPage.cshtml.cs index 1ff35d35..9e01566b 100644 --- a/ProjectLighthouse/Pages/PhotosPage.cshtml.cs +++ b/ProjectLighthouse/Pages/PhotosPage.cshtml.cs @@ -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 Photos; + + public async Task OnGet() + { + this.PhotoCount = await StatisticsHelper.PhotoCount(); + + this.Photos = await this.Database.Photos.Include(p => p.Creator).Take(20).ToListAsync(); + + return this.Page(); + } } } \ No newline at end of file