Copied to clipboard

Flag this post as spam?

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


  • SideSam 13 posts 33 karma points
    Jan 12, 2012 @ 14:54
    SideSam
    0

    Member.BeforeSave and Member.AfterSave events fire with same data

    Hi all,

    I need to have something where i have two versions of member property values:

    1. Ones that existed before save occured (old values) - those that you can see when you open a member in backend.
    2. And ones that exist after member is saved (new values) - those that somebody entered/edited in backend.
    Here is how i expect the code to work:
    public class EventExample : ApplicationBase
    {
        public EventExample()
        {
            Member.BeforeSave += new Member.SaveEventHandler(MemberBeforeSave);
            Member.AfterSave += new Member.SaveEventHandler(MemberAfterSave);
        }
    
        private void MemberBeforeSave(Member sender, umbraco.cms.businesslogic.SaveEventArgs asgs)
        {
            //this is expected to fire with values of properties on sender that existed before user clicked save button in Umbraco backend.
        }
    
        private void MemberAfterSave(Member sender, umbraco.cms.businesslogic.SaveEventArgs asgs)
        {
            //this is expected to fire with new values of properties that will be saved to database.
        }
    }

    Does anybody have any idea how can I make this work? Or maybe there are workarounds?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 17, 2012 @ 10:58
    Rodion Novoselov
    0

    Hi. This behaviour is by implementation since when saving a member first the membership provider updates the database and only than before and after events are raised. If you need to access the initial member state when saving  I think you could inherit UmbracoMembershipProvider and override the Update method so that to intercept database update.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 17, 2012 @ 11:01
    Jeroen Breuer
    0

    Hello,

    Rodion is right. Have a look at this blog: http://www.aaron-powell.com/the-great-umbraco-api-misconception.

    Even in the before save event the data has already been saved to the database. This will probably be fixed in Umbraco 5.

    Jeroen

  • SideSam 13 posts 33 karma points
    Jan 23, 2012 @ 16:28
    SideSam
    0

    Thanks, for replys.

    I suspected something similar. These event work fine with Documents but not so well with Members.

    I will probably rely on Rodion's workaround/hack for this.

Please Sign in or register to post replies

Write your reply to:

Draft