Esempio n. 1
0
        public ActionResult UnfeatureComment(FeatureCommentViewModel post)
        {
            if (this.User == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (post.Article == null || post.Comment == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var article = ArticleModel.GetArticleById((int)post.Article);

            if (article == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            if (!this.User.IsAdmin && this.User.Identity.Name != article.Author.Slug)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (!DB.Articles_UnfeatureComment(article.Id, post.Comment).Value)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            return(RedirectToRoute("ArticleCommentsAdmin", new { id = article.Id }));
        }
Esempio n. 2
0
        public ActionResult ApproveComment(FeatureCommentViewModel post)
        {
            if (this.User == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (post.Article == null || post.Comment == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var article = ArticleModel.GetArticleById((int)post.Article);

            if (article == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            if (!this.User.IsAdmin && this.User.Identity.Name != article.Author.Slug)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (!DB.Articles_ApproveComment(article.Id, post.Comment).Value)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!string.IsNullOrEmpty(Request.QueryString["no-redirect"]))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Accepted));
            }
            return(RedirectToRoute("CommentModerationAdmin"));
        }
Esempio n. 3
0
        public ActionResult EditComment(int article, int comment, string body, string name)
        {
            var articleModel = ArticleModel.GetArticleById(article);

            if (articleModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var commentModel = CommentModel.GetCommentById(comment);

            if (commentModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            if (body == null)
            {
                body = commentModel.BodyRaw;
                name = commentModel.Username;
                return(View(new EditCommentViewModel {
                    Article = articleModel, Comment = commentModel, Post = new CommentFormModel {
                        Body = body, Name = name
                    }
                }));
            }
            StoredProcs.Comments_CreateOrUpdateComment(comment, article, body, name, commentModel.PublishedDate, commentModel.UserIP, commentModel.UserToken, commentModel.ParentCommentId).ExecuteNonQuery();
            return(RedirectToRoute("ArticleCommentsAdmin", new { id = articleModel.Id }));
        }
Esempio n. 4
0
        public ActionResult ViewArticleById(int id)
        {
            var article = ArticleModel.GetArticleById(id);

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

            return(Redirect(article.Url));
        }
Esempio n. 5
0
        public ActionResult ViewArticleById(int id, bool onlyBodyAndAdHtml = false)
        {
            var article = ArticleModel.GetArticleById(id);

            if (article == null)
            {
                return(ErrorStatus(HttpStatusCode.NotFound, "Invalid Id"));
            }

            return(FormatOutput(article, onlyBodyAndAdHtml));
        }
Esempio n. 6
0
        public string ViewArticleById(int id, bool onlyBodyAndAdHtml = false)
        {
            var article = ArticleModel.GetArticleById(id);

            if (article == null)
            {
                return(ErrorStatus("Invalid Id"));
            }

            return(FormatOutput(article, onlyBodyAndAdHtml));
        }
Esempio n. 7
0
        public EditArticleViewModel(int?articleId)
        {
            if (articleId != null)
            {
                this.Article = ArticleModel.GetArticleById((int)articleId);
            }
            else
            {
                this.Article = new ArticleModel();
            }

            if (this.Article.PublishedDate != null)
            {
                this.Date = this.Article.PublishedDate.Value.Date.ToShortDateString();
                this.Time = this.Article.PublishedDate.Value.TimeOfDay.ToString();
            }
        }
Esempio n. 8
0
        public EditArticleViewModel(int?articleId)
        {
            if (articleId != null)
            {
                this.Article = ArticleModel.GetArticleById((int)articleId);
            }
            else
            {
                this.Article = new ArticleModel();
            }

            if (this.Article.PublishedDate != null)
            {
                this.Date = this.Article.PublishedDate.Value.Date.ToShortDateString();
                this.Time = this.Article.PublishedDate.Value.TimeOfDay.ToString();
            }

            this.UseCustomSlug = !string.Equals(Regex.Replace(this.Article.Title ?? "", @"[^a-z0-9_]+", "-", RegexOptions.IgnoreCase).Trim('-'), this.Article.Slug ?? "", StringComparison.OrdinalIgnoreCase);
        }
Esempio n. 9
0
        public ActionResult ArticleComments(int id, int page)
        {
            if (this.User == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            var article = ArticleModel.GetArticleById(id);

            if (article == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            if (this.User.IsAdmin)
            {
                return(View(new ArticleCommentsViewModel(article, page, true)));
            }
            if (this.User.Identity.Name != article.Author.Slug)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            return(View(new ArticleCommentsViewModel(article, page, false)));
        }
Esempio n. 10
0
        public ActionResult EditComment(int article, int comment, string body, string name)
        {
            var articleModel = ArticleModel.GetArticleById(article);

            if (articleModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var commentModel = CommentModel.GetCommentById(comment);

            if (commentModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            if (body == null)
            {
                body = commentModel.BodyRaw;
                name = commentModel.Username;
                return(View(new EditCommentViewModel {
                    Article = articleModel, Comment = commentModel, Post = new CommentFormModel {
                        Body = body, Name = name
                    }
                }));
            }

            DB.Comments_CreateOrUpdateComment(
                Article_Id: article,
                Body_Html: body,
                User_Name: name,
                Posted_Date: commentModel.PublishedDate,
                User_IP: commentModel.UserIP,
                User_Token: commentModel.UserToken,
                Parent_Comment_Id: commentModel.ParentCommentId,
                Comment_Id: comment
                );

            return(RedirectToRoute("ArticleCommentsAdmin", new { id = articleModel.Id }));
        }