Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattbrailsford/63e9fe6863e18cd71f0be7b6b40f03b8 to your computer and use it in GitHub Desktop.
Save mattbrailsford/63e9fe6863e18cd71f0be7b6b40f03b8 to your computer and use it in GitHub Desktop.
Untested example of checking what's changed between revisions of a IContent save event handler in Umbraco.
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace My.App.Events
{
public class MyContentSmellerEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Saving += ContentService_Saving;
}
private static void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
{
foreach (var savedEntity in e.SavedEntities)
{
var modifiedProperties = savedEntity.GetDirtyUserProperties();
if (modifiedProperties.Any())
{
var lastVersion = sender.GetVersions(savedEntity.Id).OrderByDescending(x => x.UpdateDate).FirstOrDefault();
if (lastVersion != null) {
//Zhu li, do the thing!
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment