示例#1
0
 public ArticlePage(
     ArticleSlug articleSlug,
     Article article,
     ArticleRevision articleRevision = null,
     ArticleRedirect articleRedirect = null)
     : base(articleSlug, article, articleRevision, articleRedirect)
 {
     this.PopulateArticleRevision(articleRevision);
 }
示例#2
0
        private void PopulateArticleRevision(ArticleRevision articleRevision)
        {
            if (articleRevision == null)
            {
                return;
            }

            this.ArticleRevisionMarkdownContent = articleRevision.MarkdownContent;
        }
示例#3
0
        public static string CreateArticleRevisionId(ArticleRevision articleRevision)
        {
            if (articleRevision == null)
            {
                throw new ArgumentNullException("articleRevision");
            }

            return(CreateArticleRevisionId(articleRevision.ArticleId, articleRevision.CreatedAt));
        }
示例#4
0
        public ArticleResult SaveArticleRevision(
            ArticleId articleId,
            ArticleRevision articleRevision,
            bool publishRevision = false)
        {
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }
            if (articleRevision == null)
            {
                throw new ArgumentNullException("articleRevision");
            }

            var article = this.GetArticle(articleId) ?? new Article(articleId);

            return(this.SaveArticle(article, articleRevision, publishRevision));
        }
示例#5
0
        public ArticlePageBase(
            ArticleSlug articleSlug,
            Article article,
            ArticleRevision articleRevision = null,
            ArticleRedirect articleRedirect = null)
        {
            this.ArticleSlug = articleSlug;

            PopulateArticle(article);
            PopulateArticleRevision(articleRevision);
            PopulateArticleRedirect(articleRedirect);

            this.ArticleAccess = this.ArticleAccess ?? ArticleAccess.Default();
            this.ArticleSlug = this.ArticleSlug ?? ArticleSlug.Empty;
            this.ArticleTags = this.ArticleTags ?? Enumerable.Empty<string>();
            this.ArticleRevisionDate = this.ArticleRevisionDate ?? ArticleRevisionDate.Empty;
            this.RedirectedFromArticleSlug = this.RedirectedFromArticleSlug ?? ArticleSlug.Empty;
            this.ArticleRevisionOutboundArticleSlugs = this.ArticleRevisionOutboundArticleSlugs
                                                       ?? Enumerable.Empty<string>();
        }
示例#6
0
        public ArticleResult SaveArticle(
            Article article,
            ArticleRevision articleRevision = null,
            bool publishRevision            = false)
        {
            if (article == null)
            {
                throw new ArgumentNullException("article");
            }

            if (string.IsNullOrWhiteSpace(article.Id))
            {
                this.CurrentSession.Store(article);
            }

            this.SaveArticleRevisionInternal(article, articleRevision, publishRevision);

            this.RemoveArticleRedirect(article);

            this.CurrentSession.SaveChanges();

            return(new ArticleResult(article, articleRevision));
        }
示例#7
0
        private void SaveArticleRevisionInternal(Article article, ArticleRevision articleRevision, bool publishRevision)
        {
            if (articleRevision == null || string.IsNullOrWhiteSpace(articleRevision.MarkdownContent))
            {
                return;
            }

            var activeRevision = this.GetArticleRevision(article.ActiveRevisionId);

            if (activeRevision != null && activeRevision.MarkdownContent == articleRevision.MarkdownContent)
            {
                return;
            }

            articleRevision.ArticleId = article.Id;

            this.CurrentSession.Store(articleRevision);

            if (publishRevision)
            {
                article.ActiveRevisionId        = articleRevision.Id;
                articleRevision.LastPublishedAt = DateTime.UtcNow;
            }
        }
示例#8
0
        public ArticleRevision SaveArticleRevision(ArticleSlug articleSlug, string markdownContent, string editSummary)
        {
            AssertArticleSlug(articleSlug);

            var article = this.TryGetArticle(articleSlug) ?? new Article(articleSlug);
            this.SaveArticle(article);

            var articleRevision = new ArticleRevision(
                articleSlug,
                this.currentPrincipal,
                this.currentIpAddress,
                markdownContent,
                editSummary);

            if (string.IsNullOrWhiteSpace(markdownContent))
            {
                return null;
            }

            var activeArticleRevision = this.GetLatestArticleRevision(article.Id);

            bool isContentEqualToActiveRevision = (activeArticleRevision != null)
                                                  && (activeArticleRevision.MarkdownContent
                                                      == articleRevision.MarkdownContent);
            if (isContentEqualToActiveRevision)
            {
                return null;
            }

            articleRevision.ArticleId = article.Id;
            this.CurrentSession.Store(articleRevision);

            article.ActiveArticleRevisionId = articleRevision.Id;

            return articleRevision;
        }
示例#9
0
        private void PopulateArticleRevision(ArticleRevision articleRevision)
        {
            if (articleRevision == null)
            {
                return;
            }

            this.ArticleRevisionId = articleRevision.Id;
            this.ArticleRevisionEditSummary = articleRevision.EditSummary;
            this.ArticleRevisionOutboundArticleSlugs = articleRevision.OutboundArticleSlugs;
        }