public int CreatePollComment(CommentForm commentForm) { commentForm.YourName = commentForm.YourName.IsNullEmptyOrWhitespace() ? "Anonymous" : commentForm.YourName; commentForm.IsAdminComment = false; return PollRepository.CreatePollComment(commentForm.ContainerId, commentForm.ParentCommentId, commentForm); }
public ActionResult View(int id, string question, CommentForm comment) { ICaptchaService captchaService = new ReCaptchaService(); comment.PassesCaptchaValidation = captchaService.PassesCaptcha(Request, BlogValues.CaptchaPrivateKey()); int replyId = Int32.TryParse(Request.QueryString["replyId"], out replyId) ? replyId : -1; bool replyWithQuote = Boolean.TryParse(Request.QueryString["replyWithQuote"], out replyWithQuote) ? replyWithQuote : false; comment.ContainerId = id; comment.IpAddress = Request.UserHostAddress; comment.ParentCommentId = replyId != -1 ? (int?)replyId : null; int commentId = -1; if (comment.IsValid(new ModelStateWrapper(ModelState))) { commentId = PollService.CreatePollComment(comment); Response.Redirect("/Poll/" + id + "/" + question + "?fadeComment=" + commentId + "#comments"); } PollDetailView pollDetail = PollService.GetPoll(id, -1, false, -1); pollDetail.CommentForm = comment; return View("View", pollDetail); }
public BlogComment CreateBlogComment(int blogId, int? parentCommentId, CommentForm commentForm) { ISession session = NHibernateHelper.GetCurrentSession(); BlogComment comment = new BlogComment(); comment.Author = commentForm.YourName; comment.EmailAddress = commentForm.EmailAddress; comment.EmailOnReply = commentForm.EmailOnReply; comment.Website = commentForm.Website.IsNullEmptyOrWhitespace() ? null : commentForm.Website; comment.Title = commentForm.Title; comment.TextContent = commentForm.CommentText; comment.PostedDate = DateTime.Now; comment.IsAdminComment = commentForm.IsAdminComment; comment.IPAddress = commentForm.IpAddress; comment.Approved = false; comment.ApprovalKey = Guid.NewGuid().ToString(); Blog blog = session.Get<Blog>(blogId); if (blog != null) { comment.Blog = blog; if (parentCommentId != null) { BlogComment parentComment = session.CreateCriteria(typeof(BlogComment)) .Add(Restrictions.Eq("Id", parentCommentId.Value)) .Add(Restrictions.Eq("Blog.Id", blogId)) .UniqueResult<BlogComment>(); if (parentComment != null) { comment.ParentComment = parentComment; } } session.Save(comment); session.Flush(); return comment; } return null; }
public int CreatePollComment(int pollId, int? parentCommentId, CommentForm commentForm) { ISession session = NHibernateHelper.GetCurrentSession(); PollComment comment = new PollComment(); comment.Author = commentForm.YourName; comment.EmailAddress = commentForm.EmailAddress; comment.Website = commentForm.Website.IsNullEmptyOrWhitespace() ? null : commentForm.Website; comment.Title = commentForm.Title; comment.TextContent = commentForm.CommentText; comment.PostedDate = DateTime.Now; comment.IsAdminComment = commentForm.IsAdminComment; comment.IPAddress = commentForm.IpAddress; Poll poll = session.Get<Poll>(pollId); if (poll != null) { comment.Poll = poll; if (parentCommentId != null) { PollComment parentComment = session.CreateCriteria(typeof(PollComment)) .Add(Restrictions.Eq("Id", parentCommentId.Value)) .Add(Restrictions.Eq("Poll.Id", pollId)) .UniqueResult<PollComment>(); if (parentComment != null) { comment.ParentComment = parentComment; } } session.Save(comment); session.Flush(); return comment.Id; } return -1; }
public void CreateBlogComment(int blogId, int? parentCommentId, CommentForm comment) { comment.IpAddress = HttpContext.Request.UserHostAddress; comment.ContainerId = blogId; comment.IsAdminComment = false; comment.ParentCommentId = parentCommentId; comment.YourName = comment.YourName.IsNullEmptyOrWhitespace() ? "Anonymous" : comment.YourName; BlogComment blogComment = BlogRepository.CreateBlogComment(blogId, parentCommentId, comment); Uri url = HttpContext.Request.Url; string websiteUrl = "http://" + url.Host + (url.Port != 80 ? ":" + url.Port : ""); string commentValidationUrl = websiteUrl + "/CommentValidation/{0}/" + blogComment.Id + "/" + blogComment.ApprovalKey; string subject = "New Comment for blog '" + blogComment.Blog.ShortTitle + "'"; string body = "Title: '" + HttpUtility.HtmlEncode(blogComment.Title) + "'<br />" + "Author: '" + HttpUtility.HtmlEncode(blogComment.Author) + "'<br />" + "Website: '" + HttpUtility.HtmlEncode(blogComment.Website) + "'<br />" + "E-mail: '" + (blogComment.EmailAddress.IsNullEmptyOrWhitespace() ? "N/A" : HttpUtility.HtmlEncode(blogComment.EmailAddress)) + "'<br />" + "IP Address: '" + blogComment.IPAddress + "'<br />" + "<br />" + "Comment: " + BBDecoding.DecodeBlogCommentText(blogComment.TextContent) + "<br />" + "<br />" + "Posted on: " + blogComment.PostedDate.ToString("d MMMM yyyy - hh:mm:ss") + "<br />" + "<br />" + "<br />" + "<a href=\"" + String.Format(commentValidationUrl, "Approve") + "\">Approve Comment</a> | " + "<a href=\"" + String.Format(commentValidationUrl, "Delete") + "\">Delete Comment</a>"; MailAddress to = new MailAddress("*****@*****.**"); MailMessage message = new MailMessage(); message.From = new MailAddress("*****@*****.**"); message.To.Add(to); message.Subject = subject; message.Body = body; message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.SendAsync(message, null); }
public ActionResult View(int id, string blogTitle, CommentForm comment) { ICaptchaService captchaService = new ReCaptchaService(); comment.PassesCaptchaValidation = captchaService.PassesCaptcha(Request, BlogValues.CaptchaPrivateKey()); int replyId = Int32.TryParse(Request.QueryString["replyId"], out replyId) ? replyId : -1; bool replyWithQuote = Boolean.TryParse(Request.QueryString["replyWithQuote"], out replyWithQuote) ? replyWithQuote : false; int pageNumber = Int32.TryParse(Request.QueryString["page"], out pageNumber) ? pageNumber : 1; if (comment.IsValid(new ModelStateWrapper(this.ModelState))) { BlogService.CreateBlogComment(id, replyId != -1 ? (int?)replyId : null, comment); Response.Redirect("/Blog/" + id + "/" + blogTitle + "?awaitingApproval=true#postcomment"); } BlogPageView blogPageView = BlogService.GetBlogPage(id, pageNumber, replyId, replyWithQuote, false); blogPageView.CommentForm = comment; return View("View", blogPageView); }