Anyone know how to use the IsPropertyDirty() flag in events? Basically I need to do something if a member has changed a certain value on their profile. I cannot seem to get this flag to return true no matter what I do.
Tried using it in both MemberService_Saving and MemberService_Saved events but no use:
private void MemberService_Saving(IMemberService sender, SaveEventArgs<IMember> saveEventArgs)
{
foreach (var member in saveEventArgs.SavedEntities)
{
if (!member.IsPropertyDirty("yearsOfExperience")) continue;
..never gets to here...
}
}
Not sure which version you are using, but can confirm in 7.3; IsPropertyDirty returns true if that property is edited, (at least if changed via the backoffice)
Be interesting to see if your 'yearsOfExperience' property is contained in the member.GetDirtyUserProperties() list...
void MemberService_Saving(IMemberService sender, SaveEventArgs<IMember> e)
{
foreach (var member in e.SavedEntities)
{
var dirty = member.IsPropertyDirty("yearsOfExperience");
foreach (var property in member.GetDirtyUserProperties())
{
if (property == "yearsOfExperience"){
//blimey it is dirty
}
}
}
}
rule out anything stoopid like yearsOfExperience not being the alias :-)
Thanks for chiming in! I actually had made a different stoopid error which was I was trying to bind the MemberService_Saving event I created to the MemberService.Saved event handler. The method signatures are the same so there was no build error and the event fires fine - just at the Saved stage there are no dirty properties (which makes sense).
Bit of a shame as I am doing an (expensive) calculation across a group of members so I really needed it to be performed after save. I've implemented it differently in my code now so I essentially set my own dirty flag and fire the calculation when needed that way.
Thanks for your input though! It was enough to make me spot my error :-)
Using IsPropertyDirty() for members
Anyone know how to use the IsPropertyDirty() flag in events? Basically I need to do something if a member has changed a certain value on their profile. I cannot seem to get this flag to return true no matter what I do.
Tried using it in both
MemberService_Saving
andMemberService_Saved
events but no use:Hey Barry,
Not sure which version you are using, but can confirm in 7.3; IsPropertyDirty returns true if that property is edited, (at least if changed via the backoffice)
Be interesting to see if your 'yearsOfExperience' property is contained in the member.GetDirtyUserProperties() list...
rule out anything stoopid like yearsOfExperience not being the alias :-)
Hi Marc,
Thanks for chiming in! I actually had made a different stoopid error which was I was trying to bind the
MemberService_Saving
event I created to theMemberService.Saved
event handler. The method signatures are the same so there was no build error and the event fires fine - just at the Saved stage there are no dirty properties (which makes sense).Bit of a shame as I am doing an (expensive) calculation across a group of members so I really needed it to be performed after save. I've implemented it differently in my code now so I essentially set my own dirty flag and fire the calculation when needed that way.
Thanks for your input though! It was enough to make me spot my error :-)
is working on a reply...