public IActionResult Comments(SubmitCommentViewModel comment) { if (!ModelState.IsValid) { ViewBag.CommentListModel = _commentService.GetComments(); return(View(comment)); } bool isSuccess = _commentService.AddComment(comment); if (isSuccess) { return(Redirect("/Comments?Success=true")); } else { return(View(comment)); } }
public async Task <IActionResult> SubmitComment(SubmitCommentViewModel model) { try { var comment = new EditCommentViewModel() { CenterId = model.CenterId, Message = model.Message }; await _commentService.Save(comment); return(Ok()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public ActionResult PostComment(SubmitCommentViewModel comment) { var username = this.User.Identity.GetUserName(); var userId = this.User.Identity.GetUserId(); if (ModelState.IsValid) { this.Data.Comments.Add(new Comment() { AuthorId = userId, Content = comment.Content, MovieId = comment.MovieId, }); this.Data.SaveChanges(); } var viewModel = new CommentViewModel { AuthorUsername = username, Content = comment.Content }; return(PartialView("_CommentPartial", viewModel)); }
public bool AddComment(SubmitCommentViewModel comment) { if (comment.Email.Length > 9 && comment.FullName.Length > 3) { Comment newComment = new Comment() { Text = comment.Text.SanitizeText(), FullName = comment.FullName.SanitizeText(), PhoneNumber = comment.PhoneNumber.SanitizeText(), Email = comment.Email.SanitizeText(), Date = DateTime.Now, isPublic = false, isDelete = false }; db.comments.Add(newComment); db.SaveChanges(); return true; } else { return false; } }