Copied to clipboard

Flag this post as spam?

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


  • Laurence Gillian 600 posts 1219 karma points
    Jul 13, 2017 @ 08:07
    Laurence Gillian
    0

    Member Event Handler & IRememberBeingDirty

    I have an event handler that sets a property on a member when saving, however, I'd quite like to check if a property is dirty, to avoid hitting the code on every save.

    To do this, I have used, which correctly returns true / false dependant on if the property has been changed.

    bool dirtyApproval = dirtyMember.WasPropertyDirty("umbracoMemberApproved");
    

    However, when this is added into my event handler, the SetValue and Save events no longer do anything. The weird thing is, all the code is reached, so it should be working!

    if (saved.IsApproved && dirtyApproval)
    {
        saved.SetValue("validateGUID", "RATPig");
        sender.Save(saved, false);
    }
    

    I am hooking into:

    MemberService.Saved += MemberService_Saved;
    
  • Laurence Gillian 600 posts 1219 karma points
    Jul 13, 2017 @ 09:12
    Laurence Gillian
    0

    So I'm seeing some rather strange behaviour here...

    .isApproved, seems to be unreliable, it often returns true, even when the is approved box is unticked on the profile.

    I started using .HasProperty("umbracoMemberApproved"), which has it's own quirks!

                    // Tests, Save Member
                    // Approval Checkbox state, hasProperty return value.
    
                    // false = false
                    // true = true
                    // true, 2nd save = false
                    // true, 3rd save = false
                    // false, 1st save after state change = false
                    // true, 1st save after state change = true
                    // true, 2nd save = false
    

    This means I can do...

    bool approved = saved.HasProperty("umbracoMemberApproved") ? (saved.Properties["umbracoMemberApproved"].Value.ToString() == "1") : false;
    

    When allows me to detect when the value of umbracoMemberApproved changes from false to true, but doesn't fire on every other save. But will re-fire if the users becomes unApproved, and then approved again.

  • Laurence Gillian 600 posts 1219 karma points
    Sep 05, 2017 @ 07:23
    Laurence Gillian
    100

    This was resolved in the subsequent Umbraco release.

Please Sign in or register to post replies

Write your reply to:

Draft