Created
June 7, 2016 15:02
-
-
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.
This file contains 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