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();
            }
        }
 public void Dispose()
 {
     transaction?.Dispose();
 }
Esempio n. 3
0
 public void RollbackTransaction()
 {
     _httpContextAccessor.HttpContext.Response.Headers.Add(TransactionIsolationLevel, _transaction.IsolationLevel.ToString());
     _httpContextAccessor.HttpContext.Response.Headers.Add(TransactionState, "rolled-back");
     _transaction?.Dispose();
 }