Example #1
0
        protected static void BaseEndTransaction(bool rootModeInTransaction)
        {
            if (!rootModeInTransaction)
            {
                TDBContainer <ProjectDBContext> dbContainer = BIAUnity.Resolve <TDBContainer <ProjectDBContext> >();
                try
                {
                    dbContainer.db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    DBUtil.ReformatDBConstraintError(dbEx);
                }
                catch (DbUpdateException dbEx)
                {
                    DBUtil.ReformatDBUpdateError(dbEx);
                }

                if (delegateSuccesStatic != null)
                {
                    delegateSuccesStatic(rootModeInTransaction);
                }

                dbContainer.IsInTransaction = false;
            }
        }
Example #2
0
        public static bool Lock(string tableName)
        {
            try
            {
                TDBContainer <ProjectDBContext> dbContainer = BIAUnity.Resolve <TDBContainer <ProjectDBContext> >();
                dbContainer.db.Database.BeginTransaction();

                string query = "SELECT [Value] FROM [dbo].[" + tableName + "] WHERE [Name] = 'LockTable'";
                var    item  = dbContainer.db.Database.SqlQuery <string>(query).FirstOrDefault <string>();

                if (string.IsNullOrEmpty(item))
                {
                    dbContainer.db.Database.ExecuteSqlCommand("INSERT INTO [dbo].[" + tableName + "] (Name , Value) VALUES ('LockTable', 'true')");
                    dbContainer.db.Database.ExecuteSqlCommand("UPDATE [dbo].[" + tableName + "] WITH(UPDLOCK) SET Value = 'true' WHERE Name = 'LockTable'");
                    return(true);
                }
                else if (item == "false")
                {
                    dbContainer.db.Database.ExecuteSqlCommand("UPDATE [dbo].[" + tableName + "] WITH(UPDLOCK) SET Value = 'true' WHERE Name = 'LockTable'");
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
                // return false;
            }
        }
Example #3
0
        // set in Transaction if not set and return the rootModeInTransaction
        public static bool BeginTransaction()
        {
            TDBContainer <ProjectDBContext> dbContainer = BIAUnity.Resolve <TDBContainer <ProjectDBContext> >();

            if (dbContainer.IsInTransaction)
            {
                return(true);
            }

            dbContainer.IsInTransaction = true;
            return(false);
        }
Example #4
0
        public static void UnLock(string tableName)
        {
            TDBContainer <ProjectDBContext> dbContainer = BIAUnity.Resolve <TDBContainer <ProjectDBContext> >();

            try
            {
                dbContainer.db.Database.ExecuteSqlCommand("UPDATE [dbo].[" + tableName + "] SET Value = 'false' WHERE Name = 'LockTable'");
                dbContainer.db.Database.CurrentTransaction.Commit();
            }
            catch
            {
                dbContainer.db.Database.CurrentTransaction.Rollback();
            }
        }
Example #5
0
        /// <summary>
        /// Set the context for Test unit
        /// </summary>
        /// <param name="mockContext"></param>
        public static void SetMoqContext(ProjectDBContext mockContext)
        {
            TDBContainer <ProjectDBContext> dbContainer = BIAUnity.Resolve <TDBContainer <ProjectDBContext> >();

            dbContainer._db = mockContext;
        }