public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            try
            {
                await _dbContext.BeginTransactionAsync();

                await next();

                await _dbContext.CommitTransactionAsync();
            }
            catch (Exception)
            {
                _dbContext.RollbackTransaction();
                throw;
            }
        }
Esempio n. 2
0
        public TResponse Handle(TRequest message)
        {
            try
            {
                _db.BeginTransaction();

                var response = _inner.Handle(message);

                _db.CommitTransactionAsync().Wait();

                return(response);
            }
            catch (Exception)
            {
                _db.RollbackTransaction();
                throw;
            }
        }
Esempio n. 3
0
        public async Task <TResponse> Handle(TRequest message)
        {
            try
            {
                _db.BeginTransaction();

                var response = await _inner.Handle(message);

                await _db.CommitTransactionAsync();

                return(response);
            }
            catch (Exception)
            {
                _db.RollbackTransaction();
                throw;
            }
        }
Esempio n. 4
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            try
            {
                await _dbContext.BeginTransactionAsync();

                var actionExecuted = await next();

                if (actionExecuted.Exception != null && !actionExecuted.ExceptionHandled)
                {
                    _dbContext.RollbackTransaction();
                }
                else
                {
                    await _dbContext.CommitTransactionAsync();
                }
            }
            catch (Exception)
            {
                _dbContext.RollbackTransaction();
                throw;
            }
        }