/// <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();
            }
        }
 public override void DeleteArticleVersion(VersionedArticle article)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         VersionedArticleDataStore dataStore = new VersionedArticleDataStore(transaction);
         article.Deleted = true;
         dataStore.Update(article);
         transaction.Commit();
     }
 }
        /// <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);
            }
        }
Пример #4
0
 public static void DeleteArticleVersion(VersionedArticle article)
 {
     Provider.DeleteArticleVersion(article);
 }
Пример #5
0
 public abstract void DeleteArticleVersion(VersionedArticle article);