Transaction

Namespace: NPoco
We found 10 examples in language CSharp for this search. You will see 44 fragments of code.

Other methods


        public T Get<T>(dynamic id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            return (T)_dapper.Get<T>(Connection, id, transaction, commandTimeout);
        }

        public T Get<T>(Expression<Func<T, bool>> exp, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            return (T)_dapper.Get<T>(Connection, exp, transaction, commandTimeout);
        }

        public void Inserts<T>(IEnumerable<T> entities, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            _dapper.Inserts<T>(Connection, entities, transaction, commandTimeout);
        }

        public dynamic Insert<T>(T entity, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            return _dapper.Insert<T>(Connection, entity, transaction, commandTimeout);
        }

        public bool Update<T>(T entity, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            return _dapper.Update<T>(Connection, entity, transaction, commandTimeout);
        }

        public int Update<T>(dynamic updateDict, dynamic keyDict, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            transaction = transaction ?? _transaction;
            return _dapper.Update<T>(Connection, updateDict, keyDict, transaction, commandTimeout);
        }


        public void Dispose()
        {
            Transaction.Current = null;
        }

        [Fact]
        public void TransactionScopeCommit()
        {
            Assert.Null(Transaction.Current);
            using (TransactionScope scope = new TransactionScope())
            {
                Assert.NotNull(Transaction.Current);
                Assert.Equal(TransactionStatus.Active, Transaction.Current.TransactionInformation.Status);
                scope.Complete();
            }
            Assert.Null(Transaction.Current);
        }

        [Fact]
        public void TransactionScopeCompleted1()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    scope.Complete();
                    /* Can't access ambient transaction after scope.Complete */
                    TransactionStatus status = Transaction.Current.TransactionInformation.Status;
                }
            });
        }

        [Fact]
        public void TransactionScopeCompleted2()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                scope.Complete();
                Assert.Throws<InvalidOperationException>(() =>
                {
                    Transaction.Current = Transaction.Current;
                });
            }
        }


        private bool BalancesMatch()
        {
            return BalancesMatch(new List<Transaction>());
        }

        private bool BalancesMatch(IReadOnlyList<Transaction> removedTransactions)
        {
            GetTransactionsWithUpdatedConfirmation().ForEach(t => _updatedTransactions.Add(t));
            var balancesMatch = _balanceCalculator.BalanceEqualsLastTransactionBalance(_newTransactions,
                _knownTransactions, _updatedTransactions, removedTransactions, UnconfirmedBalanceNqt);
            return balancesMatch;
        }

        protected virtual void OnTransactionConfirmationUpdated(Transaction transaction)
        {
            TransactionConfirmationUpdated?.Invoke(this, transaction);
        }

        protected virtual void OnTransactionBalanceUpdated(Transaction transaction)
        {
            TransactionBalanceUpdated?.Invoke(this, transaction);
        }

        protected virtual void OnTransactionAdded(Transaction transaction)
        {
            TransactionAdded?.Invoke(this, transaction);
        }


        internal virtual Enlistment EnlistDurable(
            InternalTransaction tx,
            Guid resourceManagerIdentifier,
            IEnlistmentNotification enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            Transaction atomicTransaction
            )
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }

        internal virtual Enlistment EnlistDurable(
            InternalTransaction tx,
            Guid resourceManagerIdentifier,
            ISinglePhaseNotification enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            Transaction atomicTransaction
            )
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }

        internal virtual Enlistment EnlistVolatile(
            InternalTransaction tx,
            IEnlistmentNotification enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            Transaction atomicTransaction
            )
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }

        internal virtual Enlistment EnlistVolatile(
            InternalTransaction tx,
            ISinglePhaseNotification enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            Transaction atomicTransaction
            )
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }

        internal virtual bool EnlistPromotableSinglePhase(
            InternalTransaction tx,
            IPromotableSinglePhaseNotification promotableSinglePhaseNotification,
            Transaction atomicTransaction,
            Guid promoterType
            )
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }

        internal virtual Enlistment PromoteAndEnlistDurable(
            InternalTransaction tx,
            Guid resourceManagerIdentifier,
            IPromotableSinglePhaseNotification promotableNotification,
            ISinglePhaseNotification enlistmentNotification,
            EnlistmentOptions enlistmentOptions,
            Transaction atomicTransaction)
        {
            throw TransactionException.CreateTransactionStateException(tx._innerException, tx.DistributedTxId);
        }


        public async Task<Transaction> GetTransactionByID(int Id)
        {
            return await context.Transaction
                .FirstOrDefaultAsync(c => c.Id == Id);
        }

        public async Task<List<Transaction>> GetTransactionByBorrower(string userId, int status)
        {
            return await context.Transaction
                .Include(c => c.TransactionDetail)
                .Where(c => c.BorrowerId == userId &&
                        (c.CurrentStatus == status))
                .OrderByDescending(c => c.Id)
                .ToListAsync();
        }

        public async Task<List<Transaction>> GetReturnedItem(string userId)
        {
            return await context.Transaction
                .Where(c => c.BorrowerId == userId &&
                        (c.CurrentStatus == (int)TransactionStatusEnum.ReturnComplete))
                .ToListAsync();
        }

        public async Task<Transaction> GetRequestedItem(int itemId)
        {
            return await context.Transaction
                .Where(c => c.ItemId == itemId &&
                        c.CurrentStatus == (int)TransactionStatusEnum.Request)
                .FirstOrDefaultAsync();
        }


        public async Task<Transaction> GetCompletedItem(int itemId)
        {
            return await context.Transaction
                .Where(c => c.ItemId == itemId &&
                        c.CurrentStatus == (int)TransactionStatusEnum.ReturnComplete)
                .FirstOrDefaultAsync();
        }

        public async Task<Transaction> GetRequestReturnItem(int itemId)
        {
            return await context.Transaction
                .Where(c => c.ItemId == itemId &&
                        c.CurrentStatus == (int)TransactionStatusEnum.RequestReturn)
                .FirstOrDefaultAsync();
        }


        public IDbCommand GetDbCommand(SqlStatement sql, DataProvider provider) {
            CheckContextAreSame(provider);
            var e = provider.Driver.GetDbCommand(sql, GetConnection(provider));
            if (GetTransaction(provider) != null) {
                e.Transaction = _transaction;
            }
            return e;
        }


        internal void BeginInternal(UnsafeNativeMethods.ITransactionLocal transaction)
        {
            OleDbHResult hr;
            _transaction = new WrappedTransaction(transaction, (int)_isolationLevel, out hr);
            if (hr < 0)
            {
                _transaction.Dispose();
                _transaction = null;
                ProcessResults(hr);
            }
        }

        internal static OleDbTransaction TransactionUpdate(OleDbTransaction transaction)
        {
            if ((null != transaction) && (null == transaction._transaction))
            {
                return null;
            }
            return transaction;
        }


        protected void Dispose(bool disposing)
        {
            Transaction.Current = null;
        }

        private static string DoWork(string txId)
        {
            string txId1 = Transaction.Current != null ? Transaction.Current.TransactionInformation.LocalIdentifier : null;
            Assert.Equal(txId, txId1);

            if (s_throwExceptionDefaultOrBeforeAwait)
            {
                throw new Exception("Sync DoWork exception!");
            }

            return "Hello" + " World";
        }
        private static void AssertTransactionNull()
        {
            Assert.Null(Transaction.Current);
        }

        private static void AssertTransactionNotNull()
        {
            Assert.NotNull(Transaction.Current);
        }

        private static string AssertAndGetCurrentTransactionId()
        {
            AssertTransactionNotNull();
            return Transaction.Current.TransactionInformation.LocalIdentifier;
        }

        private static string AssertAndGetCurrentTransactionId(TransactionScopeOption scopeOption)
        {
            if (scopeOption == TransactionScopeOption.Suppress)
            {
                AssertTransactionNull();
                return null;
            }
            else
            {
                AssertTransactionNotNull();
                return Transaction.Current.TransactionInformation.LocalIdentifier;
            }
        }


        private Transaction GetTransactionOrNull(Stratis.Bitcoin.Features.Wallet.TransactionData transactionData)
        {
            try
            {
                var transaction = transactionData?.Transaction;
                return transaction;
            }
            catch
            {
                return null;
            }
        }
        private Transaction GetTransactionOrNull(Stratis.Bitcoin.Features.WatchOnlyWallet.TransactionData transactionData)
        {
            try
            {
                var transaction = transactionData?.Transaction;
                return transaction;
            }
            catch
            {
                return null;
            }
        }

        [Fact]
        public void Ctor_Default()
        {
            using (var transaction = new TestDesignerTransaction())
            {
                Assert.Empty(transaction.Description);
                Assert.False(transaction.Canceled);
                Assert.False(transaction.Committed);
            }
        }

        [Theory]
        [InlineData(null)]
        [InlineData("Description")]
        public void Ctor_Default(string description)
        {
            using (var transaction = new TestDesignerTransaction(description))
            {
                Assert.Same(description, transaction.Description);
                Assert.False(transaction.Canceled);
                Assert.False(transaction.Committed);
            }
        }

        [Fact]
        public void Cancel_NotCommitted_Success()
        {
            using (var transaction = new TestDesignerTransaction())
            {
                transaction.Cancel();
                Assert.Equal(1, transaction.CancelCount);
                Assert.True(transaction.Canceled);

                transaction.Cancel();
                Assert.Equal(1, transaction.CancelCount);
                Assert.True(transaction.Canceled);
            }
        }

        [Fact]
        public void Cancel_Committed_Success()
        {
            using (var transaction = new TestDesignerTransaction())
            {
                transaction.Commit();

                transaction.Cancel();
                Assert.Equal(0, transaction.CancelCount);
                Assert.False(transaction.Canceled);
            }
        }

        [Fact]
        public void Commit_NotCommitted_Success()
        {
            using (var transaction = new TestDesignerTransaction())
            {
                transaction.Commit();
                Assert.Equal(1, transaction.CommitCount);
                Assert.True(transaction.Committed);

                transaction.Commit();
                Assert.Equal(1, transaction.CommitCount);
                Assert.True(transaction.Committed);
            }
        }

        [Fact]
        public void Commit_Cancelled_Success()
        {
            using (var transaction = new TestDesignerTransaction())
            {
                transaction.Cancel();

                transaction.Commit();
                Assert.Equal(0, transaction.CommitCount);
                Assert.False(transaction.Committed);
            }
        }

NPoco.Transaction : ITransaction, IDisposable

Constructors :

public Transaction(IDatabase db = , IsolationLevel isolationLevel = )

Methods :

public Void Complete()
public Void Dispose()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods