comments ...

This commit is contained in:
Paul Schneider
2024-12-14 23:49:13 +00:00
parent f7b6b5e305
commit 5e5c6d57ea
6 changed files with 32 additions and 17 deletions

View File

@ -118,7 +118,7 @@ namespace Yavsc.Controllers
_context.Comment.Add(c);
try
{
await _context.SaveChangesAsync(User.GetUserId());
await _context.SaveChangesAsync(uid);
}
catch (DbUpdateException)
{

View File

@ -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<ApplicationUser>
{
@ -88,7 +90,7 @@ namespace Yavsc.Models
builder.Entity<Activity>().Property(a=>a.ParentCode).IsRequired(false);
//builder.Entity<BlogPost>().HasOne(p => p.Author).WithMany(a => a.Posts);
}
// this is not a failback procedure.
@ -202,11 +204,11 @@ namespace Yavsc.Models
public DbSet<GeneralSettings> GeneralSettings { get; set; }
public DbSet<CoWorking> 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<int> SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken))
{
AddTimestamps(userId);

View File

@ -80,11 +80,11 @@ $('#commentValidation').html(
@if (User.GetUserId()!=null) {
<div class="form-horizontal">
<div class="input-group" >
<input name="Comment" id="Comment" class="form-control" placeholder="DoCommentPlaceHolder"]"/>
<input name="Comment" id="Comment" class="form-control" placeholder="..."/>
<span class="input-group-btn">
<span id="commentValidation"></span>
<input type="button" value="DoComment"]" class="btn btn-secondary"
<input type="button" value="Comment" class="btn btn-secondary"
data-receiverId="@Model.Id" id="cmtBtn"
/>
</span>

View File

@ -1,11 +1,16 @@
@model Comment
<div data-type="blogcomment" data-id="@Model.Id" data-allow-edit="@(User.GetUserId()==Model.AuthorId?"true":"false")"
data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Html.Raw(Model.DateCreated)" data-username="@Model.Author.UserName" >
data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Model.DateCreated.ToString("yyyy-MM-dd hh:mm:ss")" data-username="@Model.Author.UserName" >
<asciidoc>@Model.Content</asciidoc>
<div class="subcomments">
@if (Model.Children!=null && Model.Children.Count>0) {
foreach (var comment in Model.Children) {
@Html.DisplayFor(model=>comment,"Comment","Comment")
} }
</div>
@if (Model.Children!=null) {
<div class="subcomments">
@foreach (var comment in Model.Children)
{
Html.DisplayFor(model=>comment,"Comment","Comment");
}
</div>
}
</div>

View File

@ -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;
}

View File

@ -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('<div class="commentmeta"><div class="avatar"><img src="/Avatars/' + username + '.xs.png" class="smalltofhol" />' + username + '</div><div class="cmtdatetime">' +
this.element.prepend('<div class="commentmeta"><img class="avatar" src="/Avatars/' + username + '.xs.png" class="smalltofhol" title="' + username + '" /><div class="cmtdatetime">' +
date.toLocaleDateString(this.options.lang) + ' ' + date.toLocaleTimeString(this.options.lang) + '</div></div>')
this.element.on("mouseenter", this.onMouseEnter);
this.element.on("mouseleave", this.onMouseLeave);
this.ctlBtn = $('<button class="btn glyphicon-collapse-down"></button>').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element);
this.ctlBtn = $('<button class="btn"><span class="ui-icon ui-icon-plus"></span></button>').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element);
},
toggleCollapse: function(_this, ev) {
_this.collapsed = !_this.collapsed;