// GET: CommentForm/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentFormModel commentFormModel = db.CommentFormModels.Find(id); if (commentFormModel == null) { return(HttpNotFound()); } //Daniel: We can populate our new view model entity with a linq query. We have a lot of flexibility var viewModel = new CommentFormViewModel { //We can reuse the comment form from a couple of lines above CommentForm = commentFormModel, //We don't want to pull back all the procedures, just the one with the same priority as our comment Procedure = (from p in db.ProcedureModels where p.Priority == commentFormModel.Priority select p).First() }; //Daniel: We can no longer pass back a comment form. We need to pass back our new view model return(View(viewModel)); // This was was we retunred before //return View(commentFormModel); }
public ActionResult HandleReplyForm(CommentFormModel comment, int parentId) { if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } IContent doc = ApplicationContext.Services.ContentService.CreateContent("Comment", parentId, "CommentItem"); doc.Name = comment.Name + " " + comment.Email + DateTime.Now.Ticks.ToString(); doc.SetValue("name", comment.Name); doc.SetValue("email", comment.Email); doc.SetValue("website", string.IsNullOrEmpty(comment.Website) ? "" : comment.Website); doc.SetValue("message", comment.Message); doc.SetValue("showComment", false); doc.SetValue("isSpam", false); doc.SetValue("isBackOffice", false); doc.CreateDate = DateTime.Now; ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(doc); TempData["IsSuccessful"] = true; return(RedirectToCurrentUmbracoPage()); }
public ActionResult DeleteConfirmed(int id) { CommentFormModel commentFormModel = db.CommentFormModels.Find(id); db.CommentFormModels.Remove(commentFormModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveComment(CommentFormModel newcomment) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var comment = Mapper.Map <CommentFormModel, Comment>(newcomment); commentService.CreateComment(comment, userId); } return(RedirectToAction("DisplayComments", new { updateId = newcomment.UpdateId })); }
public ActionResult Edit([Bind(Include = "ID,Name,Comment,Priority")] CommentFormModel commentFormModel) { if (ModelState.IsValid) { db.Entry(commentFormModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(commentFormModel)); }
public ActionResult Create([Bind(Include = "ID,Name,Comment,Priority")] CommentFormModel commentFormModel) { if (ModelState.IsValid) { db.CommentFormModels.Add(commentFormModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(commentFormModel)); }
public async Task <IActionResult> Create(int id, CommentFormModel model) { model.Content = this.html.Sanitize(model.Content); var userId = this.userManager.GetUserId(this.User); var userName = this.userManager.GetUserName(this.User); await this.comments.CreateAsync(model.Title, model.Content, userId, userName, id); this.TempData.AddSuccessMessage(string.Format(WebConstants.TempDataCreateCommentText, ModelName)); return(this.RedirectToAction("Details", "Trips", new { id })); }
// GET: CommentForm/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentFormModel commentFormModel = db.CommentFormModels.Find(id); if (commentFormModel == null) { return(HttpNotFound()); } return(View(commentFormModel)); }
public async Task <IActionResult> Edit(int id, int tripId, CommentFormModel model) { var userId = this.userManager.GetUserId(this.User); var username = this.userManager.GetUserName(this.User); await this.comments.EditAsync(id, model.Title, model.Content, userId, username); this.TempData.AddSuccessMessage(string.Format(WebConstants.TempDataEditCommentText, ModelName)); return(this.RedirectToAction("Details", "Trips", new { id = tripId })); }
public ActionResult CreateComment(CommentFormModel Form) { if (ModelState.IsValid) { var comment = (Form.Id != null ? _db.WikiComments.Find(Form.Id.Value) : null) ?? new WikiComment() { CreatedDate = DateTimeOffset.Now, WikiPage = _db.WikiPages.Find(Form.WikiPageId), }; if (comment.WikiPage != null) { comment.Text = Form.Text; comment.Author = CurrentUser; _db.WikiComments.AddOrUpdate(comment); _db.SaveChanges(); return(RedirectToAction("GetPage", new { pageId = Form.WikiPageId })); } } this.TempData["ModelState"] = ModelState; return(GetPage(Form.WikiPageId)); }
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 })); }