Skip to content

Instantly share code, notes, and snippets.

@jcdcdev
Last active February 18, 2024 23:34
Show Gist options
  • Save jcdcdev/bab488c0f497decf98fa951f87642ac3 to your computer and use it in GitHub Desktop.
Save jcdcdev/bab488c0f497decf98fa951f87642ac3 to your computer and use it in GitHub Desktop.
public class Handler(IUmbracoContextFactory umbracoContextFactory, IRelationService relationService) : INotificationHandler<ContentPublishedNotification>
{
public void Handle(ContentPublishedNotification notification)
{
using var umbracoContext = umbracoContextFactory.EnsureUmbracoContext().UmbracoContext;
foreach (var content in notification.PublishedEntities.Where(x => x.ContentType.Alias == Article.ModelTypeAlias))
{
if (umbracoContext.Content?.GetById(content.Id) is Article article)
{
relationService.Relate(article.Author.Id, article.Id, "authorToArticle");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment