public override void OnActionExecuted(ActionExecutedContext filterContext) { if (!_transaction.IsActive) { return; } if (filterContext.Exception == null) { try { filterContext.Controller.TempData["StatusAlert"] = "Karate chop!!"; _transaction.Commit(); } catch (StaleObjectStateException) { // Handle stale update here filterContext.Controller.TempData["StatusAlert"] = "The changes could not be applied since this record has been updated by another user."; // Redirect back to self. This is required in case the // action is attempting to redirect to another action. filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.RawUrl); // Allow rollback _transaction.Dispose(); } } else { _transaction.Dispose(); } }
protected override async Task <TResult> InterceptAsync <TResult>(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func <IInvocation, IInvocationProceedInfo, Task <TResult> > proceed) { MethodInfo methodInfo = invocation.MethodInvocationTarget; TransactionAttribute transactionAttribute = TransactionUtils.FindTransactionAttribute(methodInfo); bool bindingRequired = transactionAttribute != null; if (bindingRequired) { using (SessionWrapper sessionWrapper = sessionService.GetCurrentSession(transactionAttribute.ReadOnly)) { using (TransactionWrapper transactionWrapper = sessionWrapper.BuildTransaction( transactionAttribute.ReadOnly, transactionAttribute.IsolationLevel)) { TResult retObject = await proceed(invocation, proceedInfo).ConfigureAwait(false); await transactionWrapper.Commit().ConfigureAwait(false); return(retObject); } } } { TResult retObject = await proceed(invocation, proceedInfo).ConfigureAwait(false); return(retObject); } }
public void Commit() { try { transaction.Commit(); } catch { Rollback(); throw; } }
public virtual async Task Delete(long id) { using (SessionWrapper sessionWrapper = entityRepository.GetSessionWrapper()) { using (TransactionWrapper transactionWrapper = sessionWrapper.BuildTransaction()) { await entityRepository.Delete(id); await transactionWrapper.Commit(); } } }
public virtual async Task <TEntity> Update(TEntity entity) { using (SessionWrapper sessionWrapper = entityRepository.GetSessionWrapper()) { using (TransactionWrapper transactionWrapper = sessionWrapper.BuildTransaction()) { TEntity updatedEntity = await entityRepository.Update(entity); await transactionWrapper.Commit(); return(updatedEntity); } } }
public virtual async Task <TEntity> Get(long id, bool updateLater = false) { using (SessionWrapper sessionWrapper = entityRepository.GetSessionWrapper(true)) { using (TransactionWrapper transactionWrapper = sessionWrapper.BuildTransaction(true)) { TEntity entity = await entityRepository.Get(id, updateLater); await transactionWrapper.Commit(); return(entity); } } }
public virtual async Task <IList <TEntity> > LoadAll() { using (SessionWrapper sessionWrapper = entityRepository.GetSessionWrapper(true)) { using (TransactionWrapper transactionWrapper = sessionWrapper.BuildTransaction(true)) { IQueryable <TEntity> entityQuery = entityRepository.GetQueryable(sessionWrapper); List <TEntity> entities = await entityQuery.ToListAsync(); await transactionWrapper.Commit(); return(entities); } } }
public void CommitTransaction() { _httpContextAccessor.HttpContext.Response.Headers.Add(TransactionIsolationLevel, _transaction.IsolationLevel.ToString()); _httpContextAccessor.HttpContext.Response.Headers.Add(TransactionState, "committed"); _transaction?.Commit(); }