Пример #1
0
        public bool DeleteArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate)
        {
            var articleRevision = this.GetArticleRevision(articleId, revisionDate);

            if (articleRevision == null)
            {
                return(false);
            }

            this.CurrentSession.Delete(articleRevision);

            var article = this.GetArticle(articleId);

            if (article.ActiveRevisionId == articleRevision.Id)
            {
                var latestRevision =
                    this.CurrentSession.Query <ArticleRevision, ArticleRevisionsIndex>()
                    .OrderByDescending(x => x.CreatedAt)
                    .FirstOrDefault();

                article.ActiveRevisionId = (latestRevision != null) ? latestRevision.Id : null;
            }

            this.CurrentSession.SaveChanges();
            return(true);
        }
Пример #2
0
        public bool PublishArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate)
        {
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }
            if (revisionDate == null)
            {
                throw new ArgumentNullException("revisionDate");
            }

            var article = this.GetArticle(articleId);

            if (article == null)
            {
                return(false);
            }

            var articleRevision = this.GetArticleRevision(articleId, revisionDate);

            if (articleRevision == null)
            {
                return(false);
            }

            articleRevision.LastPublishedAt = DateTime.UtcNow;
            article.ActiveRevisionId        = articleRevision.Id;

            this.CurrentSession.SaveChanges();

            return(true);
        }
 public ArticleRevisionNotFoundException(
     ArticleSlug articleSlug,
     ArticleRevisionDate articleRevisionDate,
     string message = null,
     Exception innerException = null)
     : this(null, articleSlug, articleRevisionDate, message, innerException)
 {
 }
Пример #4
0
        public ArticleRevision GetArticleRevision(ArticleId articleId, ArticleRevisionDate revisionDate)
        {
            string id = (articleId != null) ? articleId.Id : null;

            string articleRevisionId = IdUtility.CreateArticleRevisionId(id, revisionDate);

            return(this.GetArticleRevision(articleRevisionId));
        }
Пример #5
0
        public static string CreateArticleRevisionId(ArticleId articleId, ArticleRevisionDate articleRevisionDate)
        {
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }
            if (articleRevisionDate == null)
            {
                throw new ArgumentNullException("articleRevisionDate");
            }

            return(CreateArticleRevisionId(articleId, articleRevisionDate.DateTime));
        }
 public ArticleRevisionNotFoundException(
     string articleRevisionId,
     ArticleSlug articleSlug = null,
     ArticleRevisionDate articleRevisionDate = null,
     string message = null,
     Exception innerException = null)
     : base(articleSlug,
         HttpStatusCode.NotFound,
         message ?? GetDefaultMessage(articleRevisionId, articleSlug, articleRevisionDate),
         innerException)
 {
     this.ArticleRevisionId = articleRevisionId;
     this.ArticleRevisionDate = articleRevisionDate;
 }
        private static string GetDefaultMessage(
            string articleRevisionId,
            ArticleSlug articleSlug,
            ArticleRevisionDate articleRevisionDate)
        {
            string message = "ArticleRevision not found.";

            if (!string.IsNullOrWhiteSpace(articleRevisionId))
            {
                message += string.Format(" Article Revision ID: '{0}'.", articleRevisionId);
            }
            if (articleSlug != null && articleSlug.HasValue)
            {
                message += string.Format(" Article Slug: '{0}'.", articleSlug.Slug);
            }
            if (articleRevisionDate != null && articleRevisionDate.HasValue)
            {
                message += string.Format(" Article Revision Date: '{0}'.", articleRevisionDate.DateTimeFormatted);
            }

            return message;
        }
Пример #8
0
        private ArticleRevision TryGetArticleRevision(ArticleSlug articleSlug, ArticleRevisionDate revisionDate)
        {
            var article = this.GetArticle(articleSlug);

            return (article != null) ? this.TryGetArticleRevision(article.Id, revisionDate) : null;
        }
Пример #9
0
        private ArticleRevision TryGetArticleRevision(string articleId, ArticleRevisionDate revisionDate)
        {
            var articleRevisions =
                this.CurrentSession.Query<ArticleRevisionsIndex.Result, ArticleRevisionsIndex>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                    .Where(
                        x =>
                        this.CurrentPrincipalAccessLevel >= x.CanReadAccess && x.ArticleId == articleId
                        && x.CreatedAt == revisionDate.DateTime)
                    .OfType<ArticleRevision>();

            return articleRevisions.FirstOrDefaultHandled();
        }
Пример #10
0
        private ArticleRevision GetArticleRevisionAsserted(ArticleSlug articleSlug, ArticleRevisionDate revisionDate)
        {
            AssertArticleSlug(articleSlug);
            AssertArticleRevisionDate(revisionDate, "revisionDate");

            var articleRevision = this.TryGetArticleRevision(articleSlug, revisionDate);
            if (articleRevision == null)
            {
                throw new ArticleRevisionNotFoundException(articleSlug, revisionDate);
            }

            return articleRevision;
        }
Пример #11
0
 private static void AssertArticleRevisionDate(
     ArticleRevisionDate articleRevisionDate,
     string paramName = "articleRevisionDate")
 {
     if (articleRevisionDate == null)
     {
         throw new ArgumentNullException(paramName);
     }
     if (!articleRevisionDate.HasValue)
     {
         throw new ArgumentOutOfRangeException(paramName);
     }
 }
Пример #12
0
        public ArticleRevision PublishArticleRevision(ArticleSlug articleSlug, ArticleRevisionDate revisionDate)
        {
            AssertArticleSlug(articleSlug);
            AssertArticleRevisionDate(revisionDate, "revisionDate");

            var article = this.GetArticleAsserted(articleSlug);

            var articleRevision = this.GetArticleRevisionAsserted(articleSlug, revisionDate);

            if (article.ActiveArticleRevisionId == null)
            {
                article.ActiveArticleRevisionId = articleRevision.Id;
            }

            if (article.ActiveArticleRevisionId == articleRevision.Id)
            {
                return articleRevision;
            }

            var publishedArticleRevision = articleRevision.Clone();
            publishedArticleRevision.Id = null;
            publishedArticleRevision.CreatedAt = DateTime.UtcNow;
            publishedArticleRevision.CreatedByUserName = this.currentPrincipalIdentityName;

            this.CurrentSession.Store(publishedArticleRevision);

            article.ActiveArticleRevisionId = publishedArticleRevision.Id;

            return publishedArticleRevision;
        }
Пример #13
0
 public ArticleRevision GetArticleRevision(string articleId, ArticleRevisionDate revisionDate)
 {
     return this.TryGetArticleRevision(articleId, revisionDate);
 }
Пример #14
0
        public bool DeleteArticleRevision(ArticleSlug articleSlug, ArticleRevisionDate revisionDate)
        {
            AssertArticleSlug(articleSlug);
            AssertArticleRevisionDate(revisionDate, "revisionDate");

            var articleRevision = this.TryGetArticleRevision(articleSlug, revisionDate);
            if (articleRevision == null)
            {
                return false;
            }

            this.CurrentSession.Delete(articleRevision);

            var article = this.TryGetArticle(articleSlug);
            if (article != null && article.ActiveArticleRevisionId == articleRevision.Id)
            {
                var latestRevision =
                    this.CurrentSession.Query<ArticleRevision, ArticleRevisionsIndex>()
                        .Where(x => x.ArticleId == article.Id && x.Id != articleRevision.Id)
                        .OrderByDescending(x => x.CreatedAt)
                        .FirstOrDefaultHandled();

                article.ActiveArticleRevisionId = (latestRevision != null) ? latestRevision.Id : null;
            }

            return true;
        }