创建与已发布项目的关系



我正在创建一个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

相关内容

  • 没有找到相关文章

最新更新