예제 #1
0
        /// <summary>
        /// Update the specified article. Increment the version if required.
        /// </summary>
        /// <param name="article"></param>
        /// <param name="backupVersion">If true the previous article version is saved as a backup in the VersionedArticle and the current version is incremented.</param>
        public override void UpdateArticle(Article article, bool backupVersion)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore dataStore = new ArticleDataStore(transaction);

                VersionedArticle versionedArticle = null;

                if (backupVersion)
                {
                    //Retrive the previous version (before saving the new instance) and save a versioned row

                    Article prevVersion = dataStore.FindByKey(article.Id);
                    if (prevVersion == null)
                        throw new ArticleNotFoundException(article.Id);

                    versionedArticle = new VersionedArticle(prevVersion);

                    VersionedArticleDataStore versionedStore = new VersionedArticleDataStore(transaction);
                    versionedStore.Insert(versionedArticle);

                    //Increment the current article version
                    article.IncrementVersion();
                }

                //flag the entity to be updated and attach the entity to the db
                // I must use InsertOrUpdateCopy because if backupVersion = true there is already a
                // persistent entity in the session and I must copy the values to this instance. The Update method in this case throw an exception
                article = dataStore.InsertOrUpdateCopy(article);

                transaction.Commit();
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the specified version of the article. If the version is equal the article.Version then the article is returned.
        /// </summary>
        /// <param name="article"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public override ArticleBase GetArticleByVersion(Article article, int version)
        {
            if (article.Version == version)
                return article;

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction);

                VersionedArticle versionedArticle = dataStore.FindByArticleVersion(article, version);
                if (versionedArticle == null)
                    throw new ArticleNotFoundException(article.Name + " " + version.ToString());

                return versionedArticle;
            }
        }
예제 #3
0
        /// <summary>
        /// Get a list of article versions (also with the latest version)
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public override IList<ArticleBase> GetArticleVersions(Article article)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction);

                IList<VersionedArticle> versionedArticles = dataStore.GetArticleVersions(article);

                List<ArticleBase> list = new List<ArticleBase>();

                //Add the latest version
                list.Add(article);

                //add all the other versions
                foreach (VersionedArticle verArticle in versionedArticles)
                    list.Add(verArticle);

                return list;
            }
        }
예제 #4
0
        public override void DeleteArticleVersion(VersionedArticle article)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction);

                dataStore.Delete(article.Id);

                transaction.Commit();
            }
        }