Пример #1
0
        public static Title TitleSelectExtended(SqlConnection sqlConnection, SqlTransaction sqlTransaction, int titleId)
        {
            SqlConnection connection = CustomSqlHelper.CreateConnection(
                CustomSqlHelper.GetConnectionStringFromConnectionStrings("BHL"), sqlConnection);
            SqlTransaction transaction = sqlTransaction;

            Title title = new TitleDAL().TitleSelectAuto(connection, transaction, titleId);

            if (title != null)
            {
                title.TitleCreators = Title_CreatorDAL.Title_CreatorSelectByTitle(connection, transaction, titleId);
                if (title.TitleCreators != null && title.TitleCreators.Count > 0)
                {
                    CreatorDAL creatorDAL = new CreatorDAL();
                    foreach (Title_Creator titleCreator in title.TitleCreators)
                    {
                        titleCreator.Creator = creatorDAL.CreatorSelectAuto(connection, transaction, titleCreator.CreatorID);
                    }
                }

                title.TitleIdentifiers = new Title_TitleIdentifierDAL().Title_TitleIdentifierSelectByTitleID(connection, transaction, titleId);

                title.TitleTypes = Title_TitleTypeDAL.SelectByTitle(connection, transaction, titleId);

                title.Items = ItemDAL.ItemSelectByTitleID(connection, transaction, titleId);

                title.TitleItems = new TitleItemDAL().TitleItemSelectByTitle(connection, transaction, titleId);

                title.TitleTags = TitleTagDAL.TitleTagSelectByTitle(connection, transaction, titleId);

                title.TitleAssociations = new TitleAssociationDAL().TitleAssociationSelectExtendedForTitle(connection, transaction, titleId);

                title.TitleLanguages = new TitleLanguageDAL().TitleLanguageSelectByTitleID(connection, transaction, titleId);
            }

            return(title);
        }
Пример #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 );
            }
        }
Пример #3
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);
            }
        }