我正在创建一个eventHandler,用于在多语言网站的内容中创建项目的副本。 我试图找出,如何检查该项目是否已经有关系。 请有人帮忙!
我的代码
public class CopyDocumentToRelatedOnPublish : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
base.ApplicationStarted(umbracoApplication, applicationContext);
//subscribe to the afterpublish events
Umbraco.Core.Services.ContentService.Published += ContentService_Published;
}
void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
{
var rs = ApplicationContext.Current.Services.RelationService;
var cs = ApplicationContext.Current.Services.ContentService;
foreach (IContent item in e.PublishedEntities)
{
//here is the problem!
if ()
{
cs.Copy(item, item.Id, true);
}
}
}
}
答案 0 :(得分:0)
您可以使用RelationService
上的方法AreRelated
检查现有关系
https://our.umbraco.org/documentation/reference/management/services/relationservice