Exemple #1
0
        public ActionResult GetCommentByBlogID(int id)
        {
            CommentModel objcomment = new CommentModel();
            var          result     = objcomment.GetCommentById(id);

            return(PartialView("~/Views/Blog/_Comment.cshtml", result));
        }
Exemple #2
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 }));
        }
Exemple #3
0
        public ActionResult AddComment(CommentModel objCommentModel)
        {
            CommentModel objcomment = new CommentModel();
            int          id         = objcomment.AddComment(objCommentModel);

            var result = objcomment.GetCommentById(Convert.ToInt32(objCommentModel.Blog_Id));

            SendEmailToUser(id);
            //   SendEmail(id);
            // return Json(JsonRequestBehavior.AllowGet);

            return(PartialView("~/Views/Blog/_Comment.cshtml", result));
        }
        public ActionResult Addendum(string articleSlug, int id)
        {
            var article = ArticleModel.GetArticleBySlug(articleSlug);

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

            var comment = CommentModel.GetCommentById(id);

            if (comment == null || comment.ArticleId != article.Id)
            {
                return(HttpNotFound());
            }

            if (comment.UserToken == null || comment.PublishedDate.Add(CommentEditTimeout) <= DateTime.Now)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            var cookie = Request.Cookies["tdwtf_token"];

            if (cookie == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            try
            {
                var ticket = FormsAuthentication.Decrypt(cookie.Value);
                if (ticket.Expired || comment.UserToken != ticket.UserData)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }
            catch (HttpException)
            {
                // cookie was invalid, redirect to login
                return(Redirect("/login"));
            }

            return(View(new AddendumViewModel(article, comment)));
        }
Exemple #5
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 }));
        }
Exemple #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //----- for Result -------------------
                ResultModel model  = new ResultModel();
                var         result = model.GetResult();
                Repeater2.DataSource = result;
                Repeater2.DataBind();

                //-----------    for Blog------------------
                BlogModel obj     = new BlogModel();
                int       id      = Convert.ToInt32(Request.QueryString["id"]);
                var       results = obj.getBlogbyids(id);
                hdnBlogId.Value      = Convert.ToString(id);
                ShowBlogs.DataSource = results;
                ShowBlogs.DataBind();

                //---------------------for Categories --------------------
                CategoryModel objcategoryModel = new CategoryModel();
                var           data             = objcategoryModel.GetCategory();
                Repeater1.DataSource = data;
                Repeater1.DataBind();

                //----------------------- for comments ----------------------

                CommentModel objcommentmodel = new CommentModel();
                var          items           = objcommentmodel.GetCommentById(id);
                int          totalcomment    = items.Count();
                TotalComment.Text   = Convert.ToString(totalcomment);
                comments.DataSource = items;
                comments.DataBind();
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
            }
        }
        public ActionResult Addendum(string articleSlug, int id, CommentFormModel post)
        {
            var article = ArticleModel.GetArticleBySlug(articleSlug);

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

            if (string.IsNullOrWhiteSpace(post.Body))
            {
                return(Redirect(article.Url));
            }

            var comment = CommentModel.GetCommentById(id);

            if (comment == null || comment.ArticleId != article.Id)
            {
                return(HttpNotFound());
            }

            if (comment.UserToken == null || comment.PublishedDate.Add(CommentEditTimeout) <= DateTime.Now)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            var cookie = Request.Cookies["tdwtf_token"];

            if (cookie == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            try
            {
                var ticket = FormsAuthentication.Decrypt(cookie.Value);
                if (ticket.Expired || comment.UserToken != ticket.UserData)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }
            catch (HttpException)
            {
                return(Redirect("/login"));
            }

            var addendumModel = new AddendumViewModel(article, comment)
            {
                Body = post.Body
            };

            if (post.Body.Length > addendumModel.MaxBodyLength)
            {
                ModelState.AddModelError(string.Empty, "Comment too long.");
            }
            if (ModelState.IsValid)
            {
                DB.Comments_CreateOrUpdateComment(
                    Comment_Id: comment.Id,
                    Article_Id: article.Id,
                    Body_Html: $"{comment.BodyRaw}\n\n**Addendum {DateTime.Now}:**\n{post.Body}",
                    User_Name: comment.Username,
                    Posted_Date: comment.PublishedDate,
                    User_IP: comment.UserIP,
                    User_Token: comment.UserToken,
                    Parent_Comment_Id: comment.ParentCommentId
                    );

                return(Redirect(article.Url));
            }

            return(View(addendumModel));
        }
        public async Task <ActionResult> ViewArticleComments(string articleSlug, int page, CommentFormModel form)
        {
            var article = ArticleModel.GetArticleBySlug(articleSlug);

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

            string token  = null;
            var    cookie = Request.Cookies["tdwtf_token"];

            if (cookie != null)
            {
                try
                {
                    var ticket = FormsAuthentication.Decrypt(cookie.Value);
                    if (!ticket.Expired)
                    {
                        form.Name = ticket.Name;
                        token     = ticket.UserData;
                    }
                }
                catch (HttpException)
                {
                    // cookie was invalid, redirect to login page
                    return(Redirect("/login"));
                }
            }

            if (token == null)
            {
                await this.CheckRecaptchaAsync();
            }

            var ip = Request.ServerVariables["REMOTE_ADDR"];

            if (string.IsNullOrWhiteSpace(form.Name))
            {
                ModelState.AddModelError(string.Empty, "A name is required.");
            }
            if (string.IsNullOrWhiteSpace(form.Body))
            {
                ModelState.AddModelError(string.Empty, "A comment is required.");
            }
            if (form.Parent.HasValue && CommentModel.GetCommentById(form.Parent.Value) == null)
            {
                ModelState.AddModelError(string.Empty, "Invalid parent comment.");
            }
            if (form.Body.Length > CommentFormModel.MaxBodyLength)
            {
                ModelState.AddModelError(string.Empty, "Comment too long.");
            }
            if (ModelState.IsValid)
            {
                var containsLinks = CommonMarkConverter.Parse(form.Body).AsEnumerable().Any(n => n.Inline?.Tag == CommonMark.Syntax.InlineTag.Link || n.Inline?.Tag == CommonMark.Syntax.InlineTag.Image || n.Inline?.Tag == CommonMark.Syntax.InlineTag.RawHtml || n.Block?.Tag == CommonMark.Syntax.BlockTag.HtmlBlock);
                var shouldHide    = containsLinks || DB.Comments_UserHasApprovedComment(ip, token) != true;

                int commentId = DB.Comments_CreateOrUpdateComment(
                    Article_Id: article.Id,
                    Body_Html: form.Body,
                    User_Name: form.Name,
                    Posted_Date: DateTime.Now,
                    User_IP: ip,
                    User_Token: token,
                    Parent_Comment_Id: form.Parent,
                    Hidden_Indicator: shouldHide
                    ).Value;

                return(Redirect(string.Format("{0}/{1}#comment-{2}", article.CommentsUrl, article.CachedCommentCount / ViewCommentsViewModel.CommentsPerPage + 1, commentId)));
            }

            return(View(new ViewCommentsViewModel(article, page)
            {
                Comment = form
            }));
        }