Forked from jamiepollock/MyContentSmellerEventHandler.cs
Created
June 7, 2016 15:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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