Skip to content

Instantly share code, notes, and snippets.

@jamiepollock
Created June 7, 2016 15:02
Show Gist options
  • Save jamiepollock/9e7e73cb503495cd3575fe9a7eec4930 to your computer and use it in GitHub Desktop.
Save jamiepollock/9e7e73cb503495cd3575fe9a7eec4930 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