Esempio n. 1
0
        public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, Item item, int userId)
        {
            SqlConnection  connection  = sqlConnection;
            SqlTransaction transaction = sqlTransaction;

            if (connection == null)
            {
                connection =
                    CustomSqlHelper.CreateConnection(CustomSqlHelper.GetConnectionStringFromConnectionStrings("BHL"));
            }

            bool isTransactionCoordinator = CustomSqlHelper.IsTransactionCoordinator(transaction);

            try
            {
                transaction = CustomSqlHelper.BeginTransaction(connection, transaction, isTransactionCoordinator);

                new ItemDAL().ItemManageAuto(connection, transaction, item, userId);

                if (item.Pages.Count > 0)
                {
                    PageDAL pageDAL = new PageDAL();
                    foreach (Page page in item.Pages)
                    {
                        pageDAL.PageManageAuto(connection, transaction, page, userId);
                    }
                }

                if (item.TitleItems.Count > 0)
                {
                    TitleItemDAL titleItemDAL = new TitleItemDAL();
                    foreach (TitleItem titleItem in item.TitleItems)
                    {
                        titleItemDAL.TitleItemManageAuto(connection, transaction, titleItem);
                    }
                }

                if (item.ItemLanguages.Count > 0)
                {
                    ItemLanguageDAL itemLanguageDAL = new ItemLanguageDAL();
                    foreach (ItemLanguage itemLanguage in item.ItemLanguages)
                    {
                        itemLanguageDAL.ItemLanguageManageAuto(connection, transaction, itemLanguage);
                    }
                }


                CustomSqlHelper.CommitTransaction(transaction, isTransactionCoordinator);
            }
            catch (Exception ex)
            {
                CustomSqlHelper.RollbackTransaction(transaction, isTransactionCoordinator);

                throw new Exception("Exception in Save", ex);
            }
            finally
            {
                CustomSqlHelper.CloseConnection(connection, isTransactionCoordinator);
            }
        }
Esempio n. 2
0
        public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, Item item, int userId)
        {
            SqlConnection connection = sqlConnection;
            SqlTransaction transaction = sqlTransaction;

            if ( connection == null )
            {
                connection =
                    CustomSqlHelper.CreateConnection( CustomSqlHelper.GetConnectionStringFromConnectionStrings( "BHL" ) );
            }

            bool isTransactionCoordinator = CustomSqlHelper.IsTransactionCoordinator( transaction );

            try
            {
                transaction = CustomSqlHelper.BeginTransaction( connection, transaction, isTransactionCoordinator );

                new ItemDAL().ItemManageAuto( connection, transaction, item, userId );

                if ( item.Pages.Count > 0 )
                {
                    PageDAL pageDAL = new PageDAL();
                    foreach ( Page page in item.Pages )
                    {
                        pageDAL.PageManageAuto( connection, transaction, page, userId );
                    }
                }

                if (item.TitleItems.Count > 0)
                {
                    TitleItemDAL titleItemDAL = new TitleItemDAL();
                    foreach (TitleItem titleItem in item.TitleItems)
                    {
                        titleItemDAL.TitleItemManageAuto(connection, transaction, titleItem);
                    }
                }

                if (item.ItemLanguages.Count > 0)
                {
                    ItemLanguageDAL itemLanguageDAL = new ItemLanguageDAL();
                    foreach (ItemLanguage itemLanguage in item.ItemLanguages)
                    {
                        itemLanguageDAL.ItemLanguageManageAuto(connection, transaction, itemLanguage);
                    }
                }

                CustomSqlHelper.CommitTransaction( transaction, isTransactionCoordinator );
            }
            catch ( Exception ex )
            {
                CustomSqlHelper.RollbackTransaction( transaction, isTransactionCoordinator );

                throw new Exception( "Exception in Save", ex );
            }
            finally
            {
                CustomSqlHelper.CloseConnection( connection, isTransactionCoordinator );
            }
        }