Browse Source

blogging module deleting comment

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
86aaad017f
  1. 9
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs
  3. 6
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs
  4. 28
      modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs
  5. 18
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  6. 7
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
  7. 40
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

9
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<CommentDto> 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);
}
}
}
}

2
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs

@ -10,5 +10,7 @@ namespace Volo.Blogging.Comments
Task<List<Comment>> GetListOfPostAsync(
Guid postId
);
Task<List<Comment>> GetRepliesOfComment(Guid id);
}
}

6
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<List<Comment>> GetRepliesOfComment(Guid id)
{
return await DbSet
.Where(a => a.RepliedCommentId == id).ToListAsync();
}
}
}

28
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);
}
}
}

18
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml

@ -132,7 +132,13 @@
<a href="#" class="tag" data-relpyid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
</a>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete))
{
<span class="seperator">|</span>
<a href="#" class="tag" data-deleteid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-up" aria-hidden="true"></i><span class="count count-up">44</span>
@ -176,6 +182,14 @@
<a href="#" class="tag" data-relpyid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
</a>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete))
{
<span class="seperator">|</span>
<a href="#" class="tag" data-deleteid="@reply.Id">
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-up" aria-hidden="true"></i><span class="count count-up">44</span>
@ -210,4 +224,4 @@
</div>
</div>
</div>
</div>
</div>

7
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);

40
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();
}
});
}
});

Loading…
Cancel
Save