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, PageType pageType)
        {
            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 PageTypeDAL().PageTypeManageAuto(connection, transaction, pageType);

                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. 3
0
        public PDF AddNewPdf(SqlConnection sqlConnection, SqlTransaction sqlTransaction,
                             int itemID, String emailAddress, String shareWith, bool imagesOnly,
                             String articleTitle, String articleCreators, String articleTags, List <int> pageIDs)
        {
            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);

                // Add the new pdf record
                PDF newPdf = new PDF();
                newPdf.ItemID                  = itemID;
                newPdf.EmailAddress            = emailAddress;
                newPdf.ShareWithEmailAddresses = shareWith;
                newPdf.ImagesOnly              = imagesOnly;
                newPdf.ArticleTitle            = articleTitle;
                newPdf.ArticleCreators         = articleCreators;
                newPdf.ArticleTags             = articleTags;
                newPdf.PdfStatusID             = 10;
                PDF savedpdf = new PDFDAL().PDFInsertAuto(connection, transaction, newPdf);

                // Add records for the pdf pages
                PDFPageDAL pdfPageDal = new PDFPageDAL();
                foreach (int pageID in pageIDs)
                {
                    PDFPage newPdfPage = new PDFPage();
                    newPdfPage.PdfID  = savedpdf.PdfID;
                    newPdfPage.PageID = pageID;
                    pdfPageDal.PDFPageInsertAuto(connection, transaction, newPdfPage);
                }

                CustomSqlHelper.CommitTransaction(transaction, isTransactionCoordinator);

                return(savedpdf);
            }
            catch (Exception ex)
            {
                CustomSqlHelper.RollbackTransaction(transaction, isTransactionCoordinator);
                throw new Exception("Exception in AddNewPdf", ex);
            }
            finally
            {
                CustomSqlHelper.CloseConnection(connection, isTransactionCoordinator);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public static void Save(SqlConnection sqlConnection, SqlTransaction sqlTransaction, Vault vault)
        {
            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);

                if (vault.VaultID == 0)
                {
                    using (SqlCommand command = CustomSqlHelper.CreateCommand("VaultSelectMaxID", connection, transaction))
                    {
                        using (CustomSqlHelper <int> helper = new CustomSqlHelper <int>())
                        {
                            CustomGenericList <int> list = helper.ExecuteReader(command);
                            vault.VaultID = list[0] + 1;
                        }
                    }
                }

                new VaultDAL().VaultManageAuto(connection, transaction, vault);

                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. 6
0
        public static void SaveList(SqlConnection sqlConnection, SqlTransaction sqlTransaction,
                                    CustomGenericList <PageName> pageNames)
        {
            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);

                if (pageNames.Count > 0)
                {
                    PageNameDAL pageNameDAL = new PageNameDAL();
                    foreach (PageName pageName in pageNames)
                    {
                        pageNameDAL.PageNameManageAuto(connection, transaction, pageName);
                    }
                }

                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. 7
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);
            }
        }