我正在创建一个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);
}
}
}
}
您可以使用RelationService
上的方法AreRelated
检查现有关系。https://our.umbraco.org/documentation/reference/management/services/relationservice