From 954e2b3e7e8fb4d1eb8762510e394a2286c8c9aa Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 23 Nov 2021 01:00:27 -0500 Subject: [PATCH] Add comments section to profile --- .../.idea/dataSources.xml | 2 +- ProjectLighthouse/Pages/UserPage.cshtml | 20 +++++++++++++++++++ ProjectLighthouse/Pages/UserPage.cshtml.cs | 11 ++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.idea/.idea.ProjectLighthouse/.idea/dataSources.xml b/.idea/.idea.ProjectLighthouse/.idea/dataSources.xml index c64bade5..702fe04b 100644 --- a/.idea/.idea.ProjectLighthouse/.idea/dataSources.xml +++ b/.idea/.idea.ProjectLighthouse/.idea/dataSources.xml @@ -4,7 +4,7 @@ mysql.8 true - com.mysql.cj.jdbc.Driver + com.mysql.cj.jdbc.NonRegisteringDriver jdbc:mysql://localhost:3306/lighthouse $ProjectFileDir$ diff --git a/ProjectLighthouse/Pages/UserPage.cshtml b/ProjectLighthouse/Pages/UserPage.cshtml index 579fd530..5c543e70 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml +++ b/ProjectLighthouse/Pages/UserPage.cshtml @@ -1,5 +1,6 @@ @page "/user/{userId:int}" @using LBPUnion.ProjectLighthouse.Types +@using LBPUnion.ProjectLighthouse.Types.Profiles @using LBPUnion.ProjectLighthouse.Types.Settings @model LBPUnion.ProjectLighthouse.Pages.UserPage @@ -76,4 +77,23 @@ } +} + +@if (Model.ProfileUser.Comments > 0) +{ +
+

Comments

+ @foreach (Comment comment in Model.Comments!) + { + DateTimeOffset timestamp = DateTimeOffset.FromUnixTimeSeconds(comment.Timestamp / 1000); +
+ @comment.Poster.Username: + @comment.Message +

+ @timestamp.ToString("MM/dd/yyyy @ h:mm tt") UTC +

+
+
+ } +
} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/UserPage.cshtml.cs b/ProjectLighthouse/Pages/UserPage.cshtml.cs index 2d300ada..cfde4ff7 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse/Pages/UserPage.cshtml.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; +using LBPUnion.ProjectLighthouse.Types.Profiles; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -15,7 +16,10 @@ namespace LBPUnion.ProjectLighthouse.Pages {} public User? ProfileUser; + public List? Photos; + public List? Comments; + public bool IsProfileUserHearted; public async Task OnGet([FromRoute] int userId) @@ -24,6 +28,13 @@ namespace LBPUnion.ProjectLighthouse.Pages if (this.ProfileUser == null) return this.NotFound(); this.Photos = await this.Database.Photos.OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(5).ToListAsync(); + this.Comments = await this.Database.Comments.Include + (p => p.Poster) + .Include(p => p.Target) + .OrderByDescending(p => p.Timestamp) + .Where(p => p.TargetUserId == userId) + .Take(50) + .ToListAsync(); if (this.User != null) {