示例#1
0
        public static void OpenCommentDiscussion(int articleId, int topicId)
        {
            try
            {
                var api = DiscourseHelper.CreateApi();

                api.SetVisibility(topicId, true);

                // delete the worthless auto-generated "this topic is now invisible/visible" rubbish
                var topic = api.GetTopic(topicId);
                foreach (var post in topic.Posts.Where(p => p.Type == Post.PostType.ModeratorAction))
                {
                    api.DeletePost(post.Id);
                }

                StoredProcs
                .Articles_CreateOrUpdateArticle(articleId, Discourse_Topic_Opened: YNIndicator.Yes)
                .Execute();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                          string.Format("An unknown error occurred when attempting to open the Discourse discussion. "
                                        + "Verify that the article #{0} is assigned to a valid correct topic ID (currently #{1})", articleId, topicId), ex);
            }
        }
示例#2
0
        public static int CreateCommentDiscussion(ArticleModel article)
        {
            Logger.Information("Creating comment discussion for article \"{0}\" (ID={1}).", article.Title, article.Id);

            var api = DiscourseHelper.CreateApi();

            // create topic and embed <!--ARTICLEID:...--> in the body so the hacky JavaScript
            // for the "Feature" button can append the article ID to each of its query strings
            var topic = api.CreateTopic(
                new Category(Config.Discourse.CommentCategory),
                article.Title,
                string.Format(
                    "Discussion for the article: {0}\r\n\r\n<!--ARTICLEID:{1}-->",
                    article.Url,
                    article.Id
                    )
                );

            api.SetVisibility(topic.Id, false);

            StoredProcs
            .Articles_CreateOrUpdateArticle(article.Id, Discourse_Topic_Id: topic.Id)
            .Execute();

            return(topic.Id);
        }
示例#3
0
 public static void ReassignCommentDiscussion(int articleId, int topicId)
 {
     StoredProcs
     .Articles_CreateOrUpdateArticle(
         articleId,
         Discourse_Topic_Id: topicId,
         Discourse_Topic_Opened: YNIndicator.No
         ).Execute();
 }
示例#4
0
 public static void ReassignCommentDiscussion(int articleId, int topicId)
 {
     Logger.Information("Reassigning comment discussion for article (ID={0}) and topic (ID={1}).", articleId, topicId);
     StoredProcs
     .Articles_CreateOrUpdateArticle(
         articleId,
         Discourse_Topic_Id: topicId,
         Discourse_Topic_Opened: YNIndicator.No
         ).Execute();
 }
示例#5
0
        public ActionResult EditArticle(EditArticleViewModel post)
        {
            if (string.IsNullOrEmpty(post.Article.Series.Slug))
            {
                this.ModelState.AddModelError(string.Empty, "A series is required");
            }
            if (string.IsNullOrEmpty(post.Article.Author.Slug))
            {
                this.ModelState.AddModelError(string.Empty, "An author is required");
            }
            if (!string.IsNullOrEmpty(post.Article.Author.Slug) && !this.User.IsAdmin && post.Article.Author.Slug != this.User.Identity.Name)
            {
                this.ModelState.AddModelError(string.Empty, "Only administrators can change authors.");
            }
            if (!this.ModelState.IsValid)
            {
                return(View(post));
            }

            try
            {
                if (post.OpenCommentDiscussionChecked && post.Article.DiscourseTopicId > 0)
                {
                    DiscourseHelper.OpenCommentDiscussion((int)post.Article.Id, (int)post.Article.DiscourseTopicId);
                }

                Logger.Information("Creating or updating article \"{0}\".", post.Article.Title);
                int?articleId = StoredProcs.Articles_CreateOrUpdateArticle(
                    post.Article.Id,
                    post.Article.Slug ?? this.User.Identity.Name,
                    post.PublishedDate,
                    post.Article.Status,
                    post.Article.Author.Slug,
                    post.Article.Title,
                    post.Article.Series.Slug,
                    post.Article.BodyHtml,
                    post.Article.DiscourseTopicId
                    ).Execute();

                post.Article.Id = post.Article.Id ?? articleId;

                if (post.CreateCommentDiscussionChecked)
                {
                    DiscourseHelper.CreateCommentDiscussion(post.Article);
                }

                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                post.ErrorMessage = ex.ToString();
                return(View(post));
            }
        }
示例#6
0
        public ActionResult EditArticle(EditArticleViewModel post)
        {
            if (string.IsNullOrEmpty(post.Article.Series.Slug))
            {
                this.ModelState.AddModelError(string.Empty, "A series is required");
            }
            if (string.IsNullOrEmpty(post.Article.Author.Slug))
            {
                this.ModelState.AddModelError(string.Empty, "An author is required");
            }
            if (!this.ModelState.IsValid)
            {
                return(View(post));
            }

            try
            {
                int?newlyCreatedTopicId = null;
                if (post.CreateCommentDiscussionChecked)
                {
                    newlyCreatedTopicId = DiscourseHelper.CreateCommentDiscussion(post.Article);
                }
                if (post.OpenCommentDiscussionChecked && post.Article.DiscourseTopicId > 0)
                {
                    DiscourseHelper.OpenCommentDiscussion((int)post.Article.Id, (int)post.Article.DiscourseTopicId);
                }

                StoredProcs.Articles_CreateOrUpdateArticle(
                    post.Article.Id,
                    post.Article.Slug,
                    post.PublishedDate,
                    post.Article.Status,
                    post.Article.Author.Slug,
                    post.Article.Title,
                    post.Article.Series.Slug,
                    post.Article.BodyHtml,
                    newlyCreatedTopicId ?? post.Article.DiscourseTopicId
                    ).Execute();

                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                post.ErrorMessage = ex.ToString();
                return(View(post));
            }
        }