Exemple #1
0
        public IUnitOfWorkResult CommitTransaction()
        {
            if (_transaction == null)
            {
                throw new ApplicationException("Cannot roll back a transaction while there is no transaction running.");
            }

            var res = new UnitOfWorkResult();

            try
            {
                _objectContext.SaveChanges();
                _transaction.Commit();
                ReleaseCurrentTransaction();
                res.IsError = false;
            }
            catch (Exception ex)
            {
                RollBackTransaction();
                res.IsError = true;
                res.ErrorInfo = ex;
            }

            return res;
        }
Exemple #2
0
        public IUnitOfWorkResult SaveChanges()
        {
            if (IsInTransaction)
            {
                throw new ApplicationException("A transaction is running. Call CommitTransaction instead.");
            }

            var res = new UnitOfWorkResult();

            try
            {

                _objectContext.SaveChanges();
                res.IsError = false;
            }
            catch (Exception ex)
            {
                res.IsError = true;
                res.ErrorInfo = ex;
            }

            return res;
        }