How to use MemberSavingNotification to get values from original member?
Hi
I would like to get notified when the name of a member has changed. I am running on version 10.0
How do I get the original member in MemberSavingNotification (or MemberSavedNotification) ?
public void Handle(MemberSavingNotification notification)
{
var entities = notification.SavedEntities;
// do stuff
The member obejcts in notification.SavedEntities is the updated object, and do not have the original values. I need access to the original object, so I can see what properties has changes.
Or is there another way to get the original member object?
public void Handle(MemberSavingNotification notification)
{
var entities = notification.SavedEntities;
// do stuff
foreach(var entity in entities)
{
var dirty = (IRememberBeingDirty)entity;
var nameChanged = dirty.WasPropertyDirty("name");
}
I'm not entirely sure if you can use "name" but have a look in the debugger and see what it looks like.
To other readers of this thread; there are two small issues:
The code has to be located in the 'after' notification to mark the properties are dirty. So use the MemberSavedNotification.
Find the name of the property in the debugger.
The code now looks like this:
public void Handle(MemberSavedNotification notification)
{
var entities = notification.SavedEntities;
foreach (var entity in entities)
{
var dirty = (IRememberBeingDirty)entity;
var nameChanged = dirty.WasPropertyDirty("Name");
if (nameChanged)
{
_logger.LogInformation("Name has changed");
}
}
How to use MemberSavingNotification to get values from original member?
Hi
I would like to get notified when the name of a member has changed. I am running on version 10.0
How do I get the original member in MemberSavingNotification (or MemberSavedNotification) ?
The member obejcts in notification.SavedEntities is the updated object, and do not have the original values. I need access to the original object, so I can see what properties has changes.
Or is there another way to get the original member object?
Thanks,
You should be able to cast the entity to see which properties are dirty: https://our.umbraco.com/documentation/reference/events/determining-new-entity
Something like:
I'm not entirely sure if you can use
"name"
but have a look in the debugger and see what it looks like.Perfekt Sebastiaan! That solved the problem.
To other readers of this thread; there are two small issues:
The code now looks like this:
Thanks
is working on a reply...