diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs index 60535031f..caf1a10dc 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Models/CommentsHandler.cs @@ -1,4 +1,6 @@ -using JetBrains.Annotations; +using System.Linq; +using JetBrains.Annotations; +using Orchard.Comments.Services; using Orchard.Data; using Orchard.ContentManagement.Handlers; @@ -7,7 +9,8 @@ namespace Orchard.Comments.Models { public class HasCommentsHandler : ContentHandler { public HasCommentsHandler( IRepository commentsRepository, - IRepository hasCommentsRepository) { + IRepository hasCommentsRepository, + ICommentService commentService) { Filters.Add(new ActivatingFilter("sandboxpage")); Filters.Add(new ActivatingFilter("blogpost")); @@ -21,8 +24,14 @@ namespace Orchard.Comments.Models { OnLoading((context, comments) => { comments.Comments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Approved); }); + + OnRemoved((context, c) => { + if (context.ContentType == "blogpost" || context.ContentType == "sandboxpage") { + //TODO: (erikpo) Once comments are content items, replace the following repository delete call to a content manager remove call + commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList().ForEach( + commentsRepository.Delete); + } + }); } - - } -} +} \ No newline at end of file