public bool OnPreUpdate(IDataInvocation invocation) { if (invocation.Entity.GetType() == typeof(Employee)) { // change the last name to a different value and proceed: ((Employee)invocation.Entity).Name.LastName = "updated"; } return(true); }
public void ExecuteOnInsert(IDataInvocation invocation) { var canProceed = true; var insertInterceptors = ResolveForInterceptor <IInsertInterceptor>(); if (insertInterceptors != null && insertInterceptors.Count() > 0) { // pre-insert interceptors: foreach (var interceptor in insertInterceptors) { #if DEBUG Type theEntity = invocation.Entity.GetType().IsProxy() ? invocation.Entity.GetType().BaseType : invocation.Entity.GetType(); _environment.Logger.DebugFormat("Intercepting insert for '{0}' " + "with interceptor '{1}' for OnPreInsert(...).", theEntity.FullName, interceptor.GetType().Name); #endif canProceed = interceptor.OnPreInsert(invocation); if (!canProceed) { break; } } if (canProceed) { // do the insert operation: ((DataInvocation)invocation).Proceed(); // post-insert interceptors: foreach (var interceptor in insertInterceptors) { #if DEBUG Type theEntity = invocation.Entity.GetType().IsProxy() ? invocation.Entity.GetType().BaseType : invocation.Entity.GetType(); _environment.Logger.DebugFormat("Intercepting insert for '{0}' " + "with interceptor '{1}' for OnPostInsert(...).", theEntity.FullName, interceptor.GetType().Name); #endif interceptor.OnPostInsert(invocation); } } } else { ((DataInvocation)invocation).Proceed(); } }
public bool OnPreInsert(IDataInvocation invocation) { if (invocation.Entity.GetType() == typeof(Employee)) { // change the last name to a different value and proceed: ((Employee)invocation.Entity).Name.LastName = "inserted"; } // return true to invoke the insert action on the entity: return(true); }
public bool OnPreDelete(IDataInvocation invocation) { if (invocation.Entity.GetType() == typeof(Employee)) { // mark the entity as deleted, but do not call proceed // or we will remove the entity from the persistance store, // we will update the entity in the persistance store with // a custom flag instead: ((Employee)invocation.Entity).IsDeleted = true; invocation.Session.Save(invocation.Entity as Employee); } // do not proceed with the delete action: return(false); }
public void OnPostDelete(IDataInvocation invocation) { // never called when OnPreDelete returns false... }
public void OnPostUpdate(IDataInvocation invocation) { }
public void OnPostInsert(IDataInvocation invocation) { }
public void OnPostDelete(IDataInvocation invocation) { }
public bool OnPreDelete(IDataInvocation invocation) { return(true); }