mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Hooked up cascade delete for tags (not yet completed).
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045868
This commit is contained in:
@@ -26,11 +26,10 @@ namespace Orchard.Comments.Models {
|
||||
comments.PendingComments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Pending).ToList();
|
||||
});
|
||||
|
||||
OnRemoved<HasComments>((context, c) => {
|
||||
//TODO: (erikpo) Once comments are content items, replace the following repository delete call to a content manager remove call
|
||||
var comments = commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList();
|
||||
comments.ForEach(commentsRepository.Delete);
|
||||
});
|
||||
OnRemoved<HasComments>(
|
||||
(context, c) =>
|
||||
commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList().ForEach(
|
||||
commentsRepository.Delete));
|
||||
}
|
||||
}
|
||||
#if false
|
||||
|
@@ -1,36 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
[UsedImplicitly]
|
||||
public class HasTagsHandler : ContentHandler {
|
||||
private readonly IRepository<Tag> _tagsRepository;
|
||||
private readonly IRepository<TagsContentItems> _tagsContentItemsRepository;
|
||||
|
||||
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
|
||||
_tagsRepository = tagsRepository;
|
||||
_tagsContentItemsRepository = tagsContentItemsRepository;
|
||||
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
||||
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
|
||||
}
|
||||
|
||||
OnLoading<HasTags>((context, ht) => {
|
||||
HasTags tags = context.ContentItem.As<HasTags>();
|
||||
tags.AllTags = tagsRepository.Table.ToList();
|
||||
IEnumerable<TagsContentItems> tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id);
|
||||
foreach (var tagContentItem in tagsContentItems) {
|
||||
Tag tag = tagsRepository.Get(tagContentItem.TagId);
|
||||
tags.CurrentTags.Add(tag);
|
||||
}
|
||||
});
|
||||
|
||||
protected override void Loading(LoadContentContext context) {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
OnRemoved<HasTags>((context, ht) => {
|
||||
tagsContentItemsRepository.Flush();
|
||||
|
||||
HasTags tags = context.ContentItem.Get<HasTags>();
|
||||
tags.AllTags = _tagsRepository.Table.ToList();
|
||||
IEnumerable<TagsContentItems> tagsContentItems = _tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id);
|
||||
foreach (var tagContentItem in tagsContentItems) {
|
||||
Tag tag = _tagsRepository.Get(tagContentItem.TagId);
|
||||
tags.CurrentTags.Add(tag);
|
||||
}
|
||||
HasTags tags = context.ContentItem.As<HasTags>();
|
||||
foreach (var tag in tags.CurrentTags) {
|
||||
if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) {
|
||||
tagsRepository.Delete(tag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,4 @@
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string TagName { get; set; }
|
||||
}
|
||||
|
||||
public class TagsContentItems {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual int TagId { get; set; }
|
||||
public virtual int ContentItemId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,7 @@
|
||||
namespace Orchard.Tags.Models {
|
||||
public class TagsContentItems {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual int TagId { get; set; }
|
||||
public virtual int ContentItemId { get; set; }
|
||||
}
|
||||
}
|
@@ -63,6 +63,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Models\TagsContentItems.cs" />
|
||||
<Compile Include="ViewModels\EditTagsViewModel.cs" />
|
||||
<Compile Include="Controllers\HomeController.cs" />
|
||||
<Compile Include="Controllers\HasTagsDriver.cs" />
|
||||
|
Reference in New Issue
Block a user