Copied to clipboard

Flag this post as spam?

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


  • docstate 1 post 21 karma points
    Nov 16, 2011 @ 14:42
    docstate
    0

    Before/after save Document Value state

    Hi, i'm currently working on something for which i need the before and after state of a property's value (Document.Text aka name) for a rename operation.

    i've looked at the Document.AfterSave/BeforeSave events but they seem to give only the currentstate.

    So is there anyway to access both value states of Text in these events or in the AbstractDataEditor.DataEditorControl.onsave?

    thanks

  • SideSam 13 posts 33 karma points
    Nov 16, 2011 @ 15:17
    SideSam
    0

    HI

    Yes, it is possible and I am doing it right now.

    Basic idea is that you subscribe to two events: Document.BeforeSave and Document.AfterSave. First event (BeforeSave) fires with sender document version that is "old" and second event (AfterSave) fires with "new" version. Then you can use "old" version to fetch data from database and update it with "new version". 

    Here I have some code:

    Events:

    Document.BeforeSave += Document_BeforeSaveHandler;
    Document.AfterSave += Document_AfterSaveHandler;
    

    Handlers:

    private void Document_BeforeSaveHandler(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
    // save sender in class field or something, call it beforeSave.
    }
    
    private void Document_AfterSaveHandler(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
    // save sender in class field, call it afterSave.
    // then you can do something like 
    databaseHelper.Update(beforeSave, afterSave);
    // and maybe set beforeSave = null; and afterSave = null;
    }
    

    That is roughly what I do and it works really well for me :)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Nov 16, 2011 @ 15:46
Please Sign in or register to post replies

Write your reply to:

Draft