From 5e5c6d57ea1b220ced324813016d109fd0fc7874 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 14 Dec 2024 23:49:13 +0000 Subject: [PATCH] comments ... --- .../Blogspot/CommentsApiController.cs | 2 +- src/Yavsc/Models/ApplicationDbContext.cs | 15 ++++++++++----- src/Yavsc/Views/Blogspot/Details.cshtml | 4 ++-- .../Shared/DisplayTemplates/Comment.cshtml | 19 ++++++++++++------- src/Yavsc/wwwroot/css/site.css | 5 +++++ src/Yavsc/wwwroot/js/comment.js | 4 ++-- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/Yavsc/ApiControllers/Blogspot/CommentsApiController.cs b/src/Yavsc/ApiControllers/Blogspot/CommentsApiController.cs index 72a4a8f4..65050d74 100644 --- a/src/Yavsc/ApiControllers/Blogspot/CommentsApiController.cs +++ b/src/Yavsc/ApiControllers/Blogspot/CommentsApiController.cs @@ -118,7 +118,7 @@ namespace Yavsc.Controllers _context.Comment.Add(c); try { - await _context.SaveChangesAsync(User.GetUserId()); + await _context.SaveChangesAsync(uid); } catch (DbUpdateException) { diff --git a/src/Yavsc/Models/ApplicationDbContext.cs b/src/Yavsc/Models/ApplicationDbContext.cs index 750f636c..2f371691 100644 --- a/src/Yavsc/Models/ApplicationDbContext.cs +++ b/src/Yavsc/Models/ApplicationDbContext.cs @@ -38,6 +38,8 @@ namespace Yavsc.Models using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Yavsc.Server.Models.Calendar; + using Yavsc.Controllers; + using Microsoft.EntityFrameworkCore.ChangeTracking; public class ApplicationDbContext : IdentityDbContext { @@ -88,7 +90,7 @@ namespace Yavsc.Models builder.Entity().Property(a=>a.ParentCode).IsRequired(false); //builder.Entity().HasOne(p => p.Author).WithMany(a => a.Posts); - + } // this is not a failback procedure. @@ -202,11 +204,11 @@ namespace Yavsc.Models public DbSet GeneralSettings { get; set; } public DbSet CoWorking { get; set; } - private void AddTimestamps(string currentUsername) + private void AddTimestamps(string userId) { var entities = ChangeTracker.Entries() - .Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity") != null + .Where(x => x.Entity.GetType().GetInterface(nameof(ITrackedEntity)) != null && (x.State == EntityState.Added || x.State == EntityState.Modified)); @@ -215,19 +217,22 @@ namespace Yavsc.Models if (entity.State == EntityState.Added) { ((ITrackedEntity)entity.Entity).DateCreated = DateTime.Now; - ((ITrackedEntity)entity.Entity).UserCreated = currentUsername; + ((ITrackedEntity)entity.Entity).UserCreated = userId; } ((ITrackedEntity)entity.Entity).DateModified = DateTime.Now; - ((ITrackedEntity)entity.Entity).UserModified = currentUsername; + ((ITrackedEntity)entity.Entity).UserModified = userId; } } + public int SaveChanges(string userId) { AddTimestamps(userId); return base.SaveChanges(); } + + public async Task SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken)) { AddTimestamps(userId); diff --git a/src/Yavsc/Views/Blogspot/Details.cshtml b/src/Yavsc/Views/Blogspot/Details.cshtml index 3552f566..3dacd1f1 100644 --- a/src/Yavsc/Views/Blogspot/Details.cshtml +++ b/src/Yavsc/Views/Blogspot/Details.cshtml @@ -80,11 +80,11 @@ $('#commentValidation').html( @if (User.GetUserId()!=null) {
- + - diff --git a/src/Yavsc/Views/Shared/DisplayTemplates/Comment.cshtml b/src/Yavsc/Views/Shared/DisplayTemplates/Comment.cshtml index 6f217fae..c07cc48d 100644 --- a/src/Yavsc/Views/Shared/DisplayTemplates/Comment.cshtml +++ b/src/Yavsc/Views/Shared/DisplayTemplates/Comment.cshtml @@ -1,11 +1,16 @@ @model Comment +
+ data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Model.DateCreated.ToString("yyyy-MM-dd hh:mm:ss")" data-username="@Model.Author.UserName" > @Model.Content -
- @if (Model.Children!=null && Model.Children.Count>0) { - foreach (var comment in Model.Children) { - @Html.DisplayFor(model=>comment,"Comment","Comment") - } } -
+ + @if (Model.Children!=null) { +
+ @foreach (var comment in Model.Children) + { + Html.DisplayFor(model=>comment,"Comment","Comment"); + } +
+} +
diff --git a/src/Yavsc/wwwroot/css/site.css b/src/Yavsc/wwwroot/css/site.css index faf983f2..c7045d16 100644 --- a/src/Yavsc/wwwroot/css/site.css +++ b/src/Yavsc/wwwroot/css/site.css @@ -24,3 +24,8 @@ div.carousel-inner > div.item > div.carousel-caption-s { img.blogphoto { max-width: 100%; max-height: 100%; } + +.cmtdatetime { + font-style: italic; + font-size: x-small; + } diff --git a/src/Yavsc/wwwroot/js/comment.js b/src/Yavsc/wwwroot/js/comment.js index 9d8ea6fe..225275dd 100644 --- a/src/Yavsc/wwwroot/js/comment.js +++ b/src/Yavsc/wwwroot/js/comment.js @@ -25,12 +25,12 @@ $.widget("psc.blogcomment", { var date = new Date(this.element.data("date")); var username = this.element.data("username"); this.editable = this.element.data("allow-edit"); - this.element.prepend('
' + username + '
' + + this.element.prepend('
' + date.toLocaleDateString(this.options.lang) + ' ' + date.toLocaleTimeString(this.options.lang) + '
') this.element.on("mouseenter", this.onMouseEnter); this.element.on("mouseleave", this.onMouseLeave); - this.ctlBtn = $('').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element); + this.ctlBtn = $('').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element); }, toggleCollapse: function(_this, ev) { _this.collapsed = !_this.collapsed;