Создать отношение к опубликованным позициям

Я создаю 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);
            }
        }
    }
}

1 ответ

Вы можете проверить существующие отношения с помощью метода AreRelated на RelationService

https://our.umbraco.org/documentation/reference/management/services/relationservice

Другие вопросы по тегам