public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, 
            TitleAssociation titleAssociation)
        {
            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<TitleAssociation> updatedTitleAssociation =
                    new TitleAssociationDAL().TitleAssociationManageAuto(connection, transaction, titleAssociation);

                if (titleAssociation.TitleAssociationIdentifiers.Count > 0)
                {
                    TitleAssociation_TitleIdentifierDAL titleAssociationTitleIdentifierDAL = new TitleAssociation_TitleIdentifierDAL();
                    foreach (TitleAssociation_TitleIdentifier titleAssociationTitleIdentifier in titleAssociation.TitleAssociationIdentifiers)
                    {
                        if (titleAssociationTitleIdentifier.TitleAssociationID == 0) titleAssociationTitleIdentifier.TitleAssociationID = updatedTitleAssociation.ReturnObject.TitleAssociationID;
                        titleAssociationTitleIdentifierDAL.TitleAssociation_TitleIdentifierManageAuto(connection, transaction, titleAssociationTitleIdentifier);
                    }
                }

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

                throw new Exception("Exception in Save", ex);
            }
            finally
            {
                CustomSqlHelper.CloseConnection(connection, isTransactionCoordinator);
            }
        }
 private void addTitleAssociation(int titleID)
 {
     Title title = (Title)Session["Title" + titleID.ToString()];
     TitleAssociation ta = new TitleAssociation();
     ta.TitleID = title.TitleID;
     ta.Active = true;
     ta.IsNew = true;
     title.TitleAssociations.Add(ta);
 }
 /// <summary>
 /// Update values in TitleAssociation. Returns an object of type TitleAssociation.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="connectionKeyName">Connection key name located in config file.</param>
 /// <param name="value">Object of type TitleAssociation.</param>
 /// <returns>Object of type TitleAssociation.</returns>
 public TitleAssociation TitleAssociationUpdateAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     string connectionKeyName,
     TitleAssociation value)
 {
     return TitleAssociationUpdateAuto(sqlConnection, sqlTransaction, connectionKeyName,
         value.TitleAssociationID,
         value.TitleID,
         value.TitleAssociationTypeID,
         value.Title,
         value.Section,
         value.Volume,
         value.Heading,
         value.Publication,
         value.Relationship,
         value.Active,
         value.AssociatedTitleID);
 }
 /// <summary>
 /// Update values in TitleAssociation. Returns an object of type TitleAssociation.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="value">Object of type TitleAssociation.</param>
 /// <returns>Object of type TitleAssociation.</returns>
 public TitleAssociation TitleAssociationUpdateAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     TitleAssociation value)
 {
     return TitleAssociationUpdateAuto(sqlConnection, sqlTransaction, "BHL", value );
 }
        /// <summary>
        /// Manage TitleAssociation object.
        /// If the object is of type CustomObjectBase, 
        /// then either insert values into, delete values from, or update values in TitleAssociation.
        /// </summary>
        /// <param name="sqlConnection">Sql connection or null.</param>
        /// <param name="sqlTransaction">Sql transaction or null.</param>
        /// <param name="connectionKeyName">Connection key name located in config file.</param>
        /// <param name="value">Object of type TitleAssociation.</param>
        /// <returns>Object of type CustomDataAccessStatus<TitleAssociation>.</returns>
        public CustomDataAccessStatus<TitleAssociation> TitleAssociationManageAuto(
            SqlConnection sqlConnection,
            SqlTransaction sqlTransaction,
            string connectionKeyName,
            TitleAssociation value)
        {
            if (value.IsNew && !value.IsDeleted)
            {

                TitleAssociation returnValue = TitleAssociationInsertAuto(sqlConnection, sqlTransaction, connectionKeyName,
                    value.TitleID,
                        value.TitleAssociationTypeID,
                        value.Title,
                        value.Section,
                        value.Volume,
                        value.Heading,
                        value.Publication,
                        value.Relationship,
                        value.Active,
                        value.AssociatedTitleID);

                return new CustomDataAccessStatus<TitleAssociation>(
                    CustomDataAccessContext.Insert,
                    true, returnValue);
            }
            else if (!value.IsNew && value.IsDeleted)
            {
                if (TitleAssociationDeleteAuto(sqlConnection, sqlTransaction, connectionKeyName,
                    value.TitleAssociationID))
                {
                return new CustomDataAccessStatus<TitleAssociation>(
                    CustomDataAccessContext.Delete,
                    true, value);
                }
                else
                {
                return new CustomDataAccessStatus<TitleAssociation>(
                    CustomDataAccessContext.Delete,
                    false, value);
                }
            }
            else if (value.IsDirty && !value.IsDeleted)
            {

                TitleAssociation returnValue = TitleAssociationUpdateAuto(sqlConnection, sqlTransaction, connectionKeyName,
                    value.TitleAssociationID,
                        value.TitleID,
                        value.TitleAssociationTypeID,
                        value.Title,
                        value.Section,
                        value.Volume,
                        value.Heading,
                        value.Publication,
                        value.Relationship,
                        value.Active,
                        value.AssociatedTitleID);

                return new CustomDataAccessStatus<TitleAssociation>(
                    CustomDataAccessContext.Update,
                    true, returnValue);
            }
            else
            {
                return new CustomDataAccessStatus<TitleAssociation>(
                    CustomDataAccessContext.NA,
                    false, value);
            }
        }
 /// <summary>
 /// Manage TitleAssociation object.
 /// If the object is of type CustomObjectBase, 
 /// then either insert values into, delete values from, or update values in TitleAssociation.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="value">Object of type TitleAssociation.</param>
 /// <returns>Object of type CustomDataAccessStatus<TitleAssociation>.</returns>
 public CustomDataAccessStatus<TitleAssociation> TitleAssociationManageAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     TitleAssociation value)
 {
     return TitleAssociationManageAuto( sqlConnection, sqlTransaction, "BHL", value  );
 }
 public void TitleAssociationSave(TitleAssociation titleAssociation)
 {
     TitleAssociationDAL.Save(null, null, titleAssociation);
 }