Blog comment comments
This commit is contained in:
@ -15,10 +15,11 @@ using Yavsc.Models;
|
|||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Yavsc.ViewModels.Manage;
|
using Yavsc.ViewModels.Manage;
|
||||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
public class ManageController : Controller
|
public class ManageController : Controller
|
||||||
{
|
{
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
@ -91,8 +92,11 @@ namespace Yavsc.Controllers
|
|||||||
: "";
|
: "";
|
||||||
|
|
||||||
var user = await GetCurrentUserAsync();
|
var user = await GetCurrentUserAsync();
|
||||||
|
|
||||||
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
|
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var model = new IndexViewModel
|
var model = new IndexViewModel
|
||||||
{
|
{
|
||||||
HasPassword = await _userManager.HasPasswordAsync(user),
|
HasPassword = await _userManager.HasPasswordAsync(user),
|
||||||
|
@ -228,7 +228,8 @@ namespace Yavsc.Controllers
|
|||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public IActionResult DeleteConfirmed(long id)
|
public IActionResult DeleteConfirmed(long id)
|
||||||
{
|
{
|
||||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id && m.GetOwnerId()== User.GetUserId());
|
var uid = User.GetUserId();
|
||||||
|
BlogPost blog = _context.Blogspot.Single(m => m.Id == id && m.AuthorId == uid );
|
||||||
|
|
||||||
_context.Blogspot.Remove(blog);
|
_context.Blogspot.Remove(blog);
|
||||||
_context.SaveChanges(User.GetUserId());
|
_context.SaveChanges(User.GetUserId());
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace Yavsc.ViewComponents {
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
|
|
||||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
|
||||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
public partial class CommentViewComponent {
|
|
||||||
|
|
||||||
private static System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.Equals(null, resourceMan)) {
|
|
||||||
System.Resources.ResourceManager temp = new System.Resources.ResourceManager(("Yavsc.Resources." + "Yavsc.ViewComponents.CommentViewComponent"), typeof(CommentViewComponent).GetTypeInfo().Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
public static System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string apiRouteCommentBlogPost {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("apiRouteCommentBlogPost", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string CommmentId {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("CommmentId", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string Comment {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("Comment", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string LastModificationDate {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("LastModificationDate", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string CreationDate {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("CreationDate", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string PostId {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("PostId", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string UserCreated {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UserCreated", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string UserModified {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UserModified", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +1,35 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Blog;
|
using Yavsc.Models.Blog;
|
||||||
|
|
||||||
namespace Yavsc.ViewComponents
|
namespace Yavsc.ViewComponents
|
||||||
{
|
{
|
||||||
public partial class CommentViewComponent : ViewComponent
|
public class CommentViewComponent : ViewComponent
|
||||||
{
|
{
|
||||||
|
private readonly ApplicationDbContext context;
|
||||||
private readonly IStringLocalizer<CommentViewComponent> localizer;
|
private readonly IStringLocalizer<CommentViewComponent> localizer;
|
||||||
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer)
|
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer,
|
||||||
|
ApplicationDbContext context
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
this.context = context;
|
||||||
this.localizer = localizer;
|
this.localizer = localizer;
|
||||||
}
|
}
|
||||||
public IViewComponentResult Invoke(IIdentified<long> longCommentable)
|
public async Task<IViewComponentResult> InvokeAsync(long id)
|
||||||
{
|
{
|
||||||
// for a BlogPost, it results in the localization 'apiRouteCommentBlogPost': blogcomments
|
var comment = await context.Comment.Include(c=>c.Children).FirstOrDefaultAsync(c => c.Id==id);
|
||||||
ViewData["apictlr"] = "/api/"+localizer["apiRouteComment"+longCommentable.GetType().Name];
|
if (comment == null)
|
||||||
return View(longCommentable.GetType().Name, new Comment{ ReceiverId = longCommentable.Id });
|
throw new InvalidOperationException();
|
||||||
|
ViewData["apictlr"] = "/api/blogcomments";
|
||||||
|
return View("Default", comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDebuggerDisplay()
|
||||||
|
{
|
||||||
|
return ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,14 @@ $('#commentValidation').html(
|
|||||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||||
@Html.DisplayFor(m=>m.Author)
|
@Html.DisplayFor(m=>m.Author)
|
||||||
@Html.DisplayFor(m=>m.Content)
|
<asciidoc>@Html.DisplayFor(m=>m.Content)</asciidoc>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="comments">
|
<div id="comments">
|
||||||
@if (Model.Comments!=null) {
|
@if (Model.Comments!=null) {
|
||||||
foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) {
|
foreach (var comment in Model.Comments.Where(c=>c.ParentId==null)) {
|
||||||
@Html.DisplayFor(model=>comment,"Comment","Comment")
|
@await Component.InvokeAsync("Comment", new { id = comment.Id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@ -45,5 +45,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@await Component.InvokeAsync("BlogIndex",new{ id = User.GetUserId() ?? "_anonymous_" })
|
@await Component.InvokeAsync("BlogIndex",new{ viewerId = User.GetUserId() ?? "_anonymous_" })
|
||||||
</div>
|
</div>
|
||||||
|
@ -1 +0,0 @@
|
|||||||
@model Comment
|
|
@ -1,6 +1,6 @@
|
|||||||
@model Comment
|
@model Comment
|
||||||
|
|
||||||
<div data-type="blogcomment" data-id="@Model.Id" data-allow-edit="@(User.GetUserId()==Model.AuthorId?"true":"false")"
|
<div data-type="blogcomment" data-id="@Model.Id" data-receiver-id="@Model.ReceiverId" data-allow-edit="@(User.GetUserId()==Model.AuthorId?"true":"false")"
|
||||||
data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Model.DateCreated.ToString("yyyy-MM-dd hh:mm:ss")" 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>
|
<asciidoc>@Model.Content</asciidoc>
|
||||||
|
|
||||||
@ -8,9 +8,9 @@
|
|||||||
<div class="subcomments">
|
<div class="subcomments">
|
||||||
@foreach (var comment in Model.Children)
|
@foreach (var comment in Model.Children)
|
||||||
{
|
{
|
||||||
Html.DisplayFor(model=>comment,"Comment","Comment");
|
@await this.Component.InvokeAsync("Comment", new { id = comment.Id});
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -17,7 +17,6 @@
|
|||||||
@await RenderSectionAsync("header", false)
|
@await RenderSectionAsync("header", false)
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
|
||||||
<partial name="_Nav" />
|
<partial name="_Nav" />
|
||||||
@RenderSection("ctxmenu", required: false)
|
@RenderSection("ctxmenu", required: false)
|
||||||
@if (ViewData["Notify"] != null)
|
@if (ViewData["Notify"] != null)
|
||||||
@ -37,14 +36,12 @@
|
|||||||
<div class="container body-container">
|
<div class="container body-container">
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
</div>
|
</div>
|
||||||
</main>
|
|
||||||
<footer class="border-top footer text-muted">
|
<footer class="border-top footer text-muted">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
© 2024 - Yavsc - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
© 2024 - Yavsc - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|
||||||
@await RenderSectionAsync("scripts", false)
|
@await RenderSectionAsync("scripts", false)
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -107,13 +107,13 @@ $.widget("psc.blogcomment", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
doCoC: function(_this, ev) {
|
doCoC: function(_this, ev) {
|
||||||
var postid = $('#cmtBtn').data('receiverid');
|
var postId = this.element.data('receiver-id');
|
||||||
var comment = _this.cmtInput.val();
|
var comment = _this.cmtInput.val();
|
||||||
var cmtid = $(_this.element).data("id");
|
var cmtId = $(_this.element).data("id");
|
||||||
var data = {
|
var data = {
|
||||||
Content: comment,
|
Content: comment,
|
||||||
ReceiverId: postid,
|
ReceiverId: postId,
|
||||||
ParentId: cmtid,
|
ParentId: cmtId,
|
||||||
AuthorId: _this.options.authorId
|
AuthorId: _this.options.authorId
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ $.widget("psc.blogcomment", {
|
|||||||
success: function(data) {
|
success: function(data) {
|
||||||
_this.cmtInput.val('');
|
_this.cmtInput.val('');
|
||||||
$('span.field-validation-valid[data-valmsg-for="Content"]').empty();
|
$('span.field-validation-valid[data-valmsg-for="Content"]').empty();
|
||||||
$('<div data-type="blogcomment" data-id="' + data.Id + '" data-allow-edit="True" data-date="' + data.DateCreated + '" data-username="' + _this.options.authorName + '">' + data.Content + '</div>')
|
$('<div data-type="blogcomment" data-id="' + data.id + '" data-allow-edit="True" data-date="' + data.dateCreated + '" data-username="' + _this.options.authorName + '">' + data.content + '</div>')
|
||||||
.blogcomment().appendTo(_this.subCmts);
|
.blogcomment().appendTo(_this.subCmts);
|
||||||
},
|
},
|
||||||
url: _this.options.apictrlr
|
url: _this.options.apictrlr
|
||||||
|
Reference in New Issue
Block a user