Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Barry Fogarty 493 posts 1129 karma points
    Nov 05, 2015 @ 09:01
    Barry Fogarty
    0

    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 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...
                }
            }
    
  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Nov 08, 2015 @ 22:45
    Marc Goodson
    101

    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...

    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 :-)

  • Barry Fogarty 493 posts 1129 karma points
    Nov 09, 2015 @ 21:38
    Barry Fogarty
    0

    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 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 :-)

Please Sign in or register to post replies

Write your reply to:

Draft