public ActionResult EditArticle(int? id)
 {
     var model = new EditArticleViewModel(id) { User = this.User };
     if (model.UserCanEdit)
         return View(model);
     else
         return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
 }
        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);
            }
        }