Logic before Save (Save no longer override)

Logic before Save (Save no longer override)

Old forum URL: forums.lhotka.net/forums/t/11718.aspx


correodemarques posted on Wednesday, November 21, 2012

In CSLA v 4.5 the method Save is no longer overridable. How can I run some logic before the actual Save takes place? Specifically I need to check a permission for which I cannot use the Authorization rules.

JonnyBee replied on Wednesday, November 21, 2012

As more and more code makes it into async/await and asyncronicity the method to override is:

   protected async virtual System.Threading.Tasks.Task<T> SaveAsync(bool forceUpdate, object userState, bool isSync)

this method will be called for both sync and async code.

    public T Save()     {       try       {         return SaveAsync(falsenulltrue).Result;       }       catch (AggregateException ex)       {         if (ex.InnerExceptions.Count > 0)           throw ex.InnerExceptions[0];         else           throw;       }     }

 

Copyright (c) Marimer LLC