예제 #1
0
        public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, Title title, 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 );

                CustomDataAccessStatus<Title> updatedTitle =
                    new TitleDAL().TitleManageAuto( connection, transaction, title, userId );

                if ( title.TitleCreators.Count > 0 )
                {
                    Title_CreatorDAL titleCreatorDAL = new Title_CreatorDAL();
                    foreach ( Title_Creator titleCreator in title.TitleCreators )
                    {
                        if (titleCreator.TitleID == 0) titleCreator.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleCreatorDAL.Title_CreatorManageAuto( connection, transaction, titleCreator, userId );
                    }
                }

                if (title.TitleTags.Count > 0)
                {
                    TitleTagDAL titleTagDAL = new TitleTagDAL();
                    foreach (TitleTag titleTag in title.TitleTags)
                    {
                        if (titleTag.TitleID == 0) titleTag.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleTagDAL.TitleTagManageAuto(connection, transaction, titleTag);
                    }
                }

                if (title.TitleIdentifiers.Count > 0)
                {
                    Title_TitleIdentifierDAL titleTitleIdentifierDAL = new Title_TitleIdentifierDAL();
                    foreach (Title_TitleIdentifier titleTitleIdentifier in title.TitleIdentifiers)
                    {
                        if (titleTitleIdentifier.TitleID == 0) titleTitleIdentifier.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleTitleIdentifierDAL.Title_TitleIdentifierManageAuto(connection, transaction, titleTitleIdentifier);
                    }
                }

                if (title.TitleAssociations.Count > 0)
                {
                    TitleAssociationDAL titleAssociationDAL = new TitleAssociationDAL();
                    foreach (TitleAssociation titleAssociation in title.TitleAssociations)
                    {
                        if (titleAssociation.TitleID == 0) titleAssociation.TitleID = updatedTitle.ReturnObject.TitleID;
                        TitleAssociationDAL.Save(connection, transaction, titleAssociation);
                    }
                }

                if (title.TitleLanguages.Count > 0)
                {
                    TitleLanguageDAL titleLanguageDAL = new TitleLanguageDAL();
                    foreach (TitleLanguage titleLanguage in title.TitleLanguages)
                    {
                        if (titleLanguage.TitleID == 0) titleLanguage.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleLanguageDAL.TitleLanguageManageAuto(connection, transaction, titleLanguage);
                    }
                }

                if ( title.TitleTypes.Count > 0 )
                {
                    Title_TitleTypeDAL titleTypeDAL = new Title_TitleTypeDAL();
                    foreach ( Title_TitleType titleType in title.TitleTypes )
                    {
                        if (titleType.TitleID == 0) titleType.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleTypeDAL.Title_TitleTypeManageAuto( connection, transaction, titleType );
                    }
                }

                if ( title.TitleItems.Count > 0 )
                {
                    ItemDAL itemDAL = new ItemDAL();
                    TitleItemDAL titleItemDAL = new TitleItemDAL();
                    foreach ( TitleItem titleItem in title.TitleItems )
                    {
                        // Update the item
                        if (titleItem.TitleID == 0) titleItem.TitleID = updatedTitle.ReturnObject.TitleID;
                        titleItemDAL.TitleItemManageAuto( connection, transaction, titleItem );
                        // Update the primary title id (stored on the Item table)
                        itemDAL.ItemUpdatePrimaryTitleID(connection, transaction, titleItem.ItemID, titleItem.PrimaryTitleID);
                    }
                }

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

                throw new Exception( "Exception in Save", ex );
            }
            finally
            {
                CustomSqlHelper.CloseConnection( connection, isTransactionCoordinator );
            }
        }
예제 #2
0
        public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, Title title, 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);

                CustomDataAccessStatus <Title> updatedTitle =
                    new TitleDAL().TitleManageAuto(connection, transaction, title, userId);

                if (title.TitleCreators.Count > 0)
                {
                    Title_CreatorDAL titleCreatorDAL = new Title_CreatorDAL();
                    foreach (Title_Creator titleCreator in title.TitleCreators)
                    {
                        if (titleCreator.TitleID == 0)
                        {
                            titleCreator.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleCreatorDAL.Title_CreatorManageAuto(connection, transaction, titleCreator, userId);
                    }
                }

                if (title.TitleTags.Count > 0)
                {
                    TitleTagDAL titleTagDAL = new TitleTagDAL();
                    foreach (TitleTag titleTag in title.TitleTags)
                    {
                        if (titleTag.TitleID == 0)
                        {
                            titleTag.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleTagDAL.TitleTagManageAuto(connection, transaction, titleTag);
                    }
                }

                if (title.TitleIdentifiers.Count > 0)
                {
                    Title_TitleIdentifierDAL titleTitleIdentifierDAL = new Title_TitleIdentifierDAL();
                    foreach (Title_TitleIdentifier titleTitleIdentifier in title.TitleIdentifiers)
                    {
                        if (titleTitleIdentifier.TitleID == 0)
                        {
                            titleTitleIdentifier.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleTitleIdentifierDAL.Title_TitleIdentifierManageAuto(connection, transaction, titleTitleIdentifier);
                    }
                }

                if (title.TitleAssociations.Count > 0)
                {
                    TitleAssociationDAL titleAssociationDAL = new TitleAssociationDAL();
                    foreach (TitleAssociation titleAssociation in title.TitleAssociations)
                    {
                        if (titleAssociation.TitleID == 0)
                        {
                            titleAssociation.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        TitleAssociationDAL.Save(connection, transaction, titleAssociation);
                    }
                }

                if (title.TitleLanguages.Count > 0)
                {
                    TitleLanguageDAL titleLanguageDAL = new TitleLanguageDAL();
                    foreach (TitleLanguage titleLanguage in title.TitleLanguages)
                    {
                        if (titleLanguage.TitleID == 0)
                        {
                            titleLanguage.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleLanguageDAL.TitleLanguageManageAuto(connection, transaction, titleLanguage);
                    }
                }

                if (title.TitleTypes.Count > 0)
                {
                    Title_TitleTypeDAL titleTypeDAL = new Title_TitleTypeDAL();
                    foreach (Title_TitleType titleType in title.TitleTypes)
                    {
                        if (titleType.TitleID == 0)
                        {
                            titleType.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleTypeDAL.Title_TitleTypeManageAuto(connection, transaction, titleType);
                    }
                }

                if (title.TitleItems.Count > 0)
                {
                    ItemDAL      itemDAL      = new ItemDAL();
                    TitleItemDAL titleItemDAL = new TitleItemDAL();
                    foreach (TitleItem titleItem in title.TitleItems)
                    {
                        // Update the item
                        if (titleItem.TitleID == 0)
                        {
                            titleItem.TitleID = updatedTitle.ReturnObject.TitleID;
                        }
                        titleItemDAL.TitleItemManageAuto(connection, transaction, titleItem);
                        // Update the primary title id (stored on the Item table)
                        itemDAL.ItemUpdatePrimaryTitleID(connection, transaction, titleItem.ItemID, titleItem.PrimaryTitleID);
                    }
                }

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

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