public IActionResult AddComment(AddComment model) { if (ModelState.IsValid) { model.OwnerId = userService.GetUserId(); if (commentManager.AddComment(model)) { return(RedirectToAction("Index", "Posts")); } } return(RedirectToAction("Index", "Posts")); }
public ActionResult AddComment(Comment comment) { try { var user = (User)Session["Login"]; var newComment = new Comment(); newComment.Text = comment.Text; newComment.ArticleId = comment.ArticleId; newComment.ParentId = comment.ParentId; commentManager.AddComment(newComment); userManager.UpdateUserComments(user.Id, newComment); return(RedirectToAction("ArticleView", new { id = comment.ArticleId })); } catch (Exception e) { ViewBag.ErrorTitle = "Server Error"; ViewBag.ErrorDescription = "Please try again later"; return(View("~/Views/Shared/ErrorPage.cshtml")); } }
public ActionResult AddComment(int id, [FromBody] CreateCommentViewModel createComment) { _logger.LogInformation("Call AddComment method with id {id}", id); var article = _articleManager.GetArticleById(id); if (article == null) { throw new EntityNotFoundException(typeof(Article), id); } var comment = MapCreateCommentToComment(createComment); comment.Date = DateTime.Now; comment.ArticleID = id; _commentManager.AddComment(comment); return(Ok()); }
public IActionResult AddComment([FromBody] Comment comment) { var currentUserId = HttpContext.User .Claims? .FirstOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier)? .Value ?? string.Empty; if (currentUserId != comment.UserId) { return(StatusCode(403, new { message = "Invalid user id" })); } var(success, message) = _commentManager.AddComment(comment); if (success) { return(Json(new { commentId = comment.CommentId, postedDate = comment.PostedDate })); } return(StatusCode(500, new { message })); }