コード例 #1
0
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);

            if (_httpContextAccessor.HttpContext != null)
            {
                /// REMOVES AN ITEM FROM ARRAY
                var remove = _contextManager.RemoveContex;
            }
            else
            {
                if (isFirst)
                {
                    UnitOfWorkContexManager.RemoveContext(Thread.CurrentThread.ManagedThreadId);
                }
            }
        }
コード例 #2
0
 public void Rollback()
 {
     if (_httpContextAccessor.HttpContext != null)
     {
         if (_contextManager.IsFirst)
         {
             if (_context.Database.CurrentTransaction != null)
             {
                 _context.Database.RollbackTransaction();
                 rollback = true;
             }
         }
     }
     else
     {
         if (_context.Database.CurrentTransaction != null && isFirst)
         {
             _context.Database.CurrentTransaction.Rollback();
             UnitOfWorkContexManager.RemoveContext(Thread.CurrentThread.ManagedThreadId);
             rollback = true;
         }
     }
 }
コード例 #3
0
        void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (_httpContextAccessor.HttpContext != null)
                    {
                        if (_context.Database.CurrentTransaction != null && !rollback && _contextManager.IsFirst)
                        {
                            try
                            {
                                _context.Database.CurrentTransaction.Commit();
                            }
                            catch
                            {
                                _context.Database.CurrentTransaction.Rollback();

                                throw;
                            }
                            finally
                            {
                                if (_contextManager.IsFirst)
                                {
                                    _context.Dispose();
                                }
                            }
                        }
                    }
                    else
                    {
                        bool isDisposed = false;
                        try
                        {
                            var id = _context.Database.CurrentTransaction.TransactionId;
                        }
                        catch
                        {
                            isDisposed = true;
                        }

                        if (!isDisposed && _context.Database.CurrentTransaction != null && !rollback && isFirst)
                        {
                            try
                            {
                                _context.Database.CurrentTransaction.Commit();
                            }
                            catch
                            {
                                _context.Database.CurrentTransaction.Rollback();
                                throw;
                            }
                            finally
                            {
                                if (isFirst)
                                {
                                    _context.Dispose();
                                    UnitOfWorkContexManager.RemoveContext(Thread.CurrentThread.ManagedThreadId);
                                }
                            }
                        }
                    }
                }
            }
            disposed = true;
        }