diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 531666bfa9..6263159480 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -61,7 +61,7 @@ namespace Volo.Blogging.Comments [Authorize(BloggingPermissions.Comments.Create)] public async Task CreateAsync(CreateCommentDto input) { - var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId,input.Text); + var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text); comment = await _commentRepository.InsertAsync(comment); @@ -84,6 +84,13 @@ namespace Volo.Blogging.Comments public async Task DeleteAsync(Guid id) { await _commentRepository.DeleteAsync(id); + + var replies = await _commentRepository.GetRepliesOfComment(id); + + foreach (var reply in replies) + { + await _commentRepository.DeleteAsync(reply.Id); + } } } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs index 841114c2af..fb91a7816e 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs @@ -10,5 +10,7 @@ namespace Volo.Blogging.Comments Task> GetListOfPostAsync( Guid postId ); + + Task> GetRepliesOfComment(Guid id); } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs index 5fc57c14b6..3713d0464d 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs @@ -23,5 +23,11 @@ namespace Volo.Blogging.Comments .OrderBy(a => a.CreationTime) .ToListAsync(); } + + public async Task> GetRepliesOfComment(Guid id) + { + return await DbSet + .Where(a => a.RepliedCommentId == id).ToListAsync(); + } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs b/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs new file mode 100644 index 0000000000..2d5298b708 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Blogging.Comments; + +namespace Volo.Blogging.Areas.Blog.Controllers +{ + [Area("Blog")] + [Route("Blog/[controller]/[action]")] + public class CommentsController : AbpController + { + private readonly ICommentAppService _commentAppService; + + public CommentsController(ICommentAppService commentAppService) + { + _commentAppService = commentAppService; + } + + [HttpPost] + public async Task Delete(Guid id) + { + await _commentAppService.DeleteAsync(id); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 6503d0a5de..5ebfafc427 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -132,7 +132,13 @@ @L["Reply"] - + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete)) + { + | + + @L["Delete"] + + } | 44 @@ -176,6 +182,14 @@ @L["Reply"] + + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete)) + { + | + + @L["Delete"] + + } | 44 @@ -210,4 +224,4 @@ - \ No newline at end of file + diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs index a653af7cff..a4736b3d4e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs @@ -62,6 +62,13 @@ namespace Volo.Blogging.Pages.Blog.Posts await GetData(); } + public async void OnDeleteAsync(Guid commentId) + { + await _commentAppService.DeleteAsync(commentId); + + await GetData(); + } + private async Task GetData() { Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js index 8225e2244f..d5308ea213 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js @@ -3,21 +3,39 @@ $('div .replyForm').hide(); $('a').click(function (event) { - var data = $(this).attr('data-relpyid'); + var linkElement = $(this); + var data = linkElement.attr('data-relpyid'); - if (data == '' || data === undefined) { - return; - } + if (data != '' && data !== undefined) { + + event.preventDefault(); - event.preventDefault(); + var div = $(this).parent().next(); - var div = $(this).parent().next(); + if (div.is(":hidden")) { + $('div .replyForm').hide(); + div.show(); + } else { + div.hide(); + } + return; + } - if (div.is(":hidden")) { - $('div .replyForm').hide(); - div.show(); - } else { - div.hide(); + var id = $(this).attr('data-deleteid'); + + if (id != '' && id !== undefined) { + + event.preventDefault(); + console.log(id); + $.ajax({ + type: "POST", + url: "/Blog/Comments/Delete", + data: { id: id }, + success: function (response) { + console.log(linkElement); + linkElement.parent().parent().parent().remove(); + } + }); } });