public IActionResult UpdateCommentReplyForCommentId(int replyId, [FromBody] CommentReplyDto commentReply, [FromHeader] int UserID, [FromHeader] string UserRole) { var currentReply = _context.CommentReplies.Find(replyId); if (currentReply == null) { return(StatusCode(StatusCodes.Status404NotFound)); } if (_user.GetUserById(UserID) == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } if (currentReply.UserId != UserID && UserRole != "Admin") { return(StatusCode(StatusCodes.Status403Forbidden)); } currentReply.Text = commentReply.Text; _context.CommentReplies.Update(currentReply); var success = _context.SaveChanges(); if (success < 1) { return(StatusCode(StatusCodes.Status400BadRequest)); } return(StatusCode(StatusCodes.Status202Accepted, new JsonResult(currentReply))); }
public IActionResult CreateReplyForCommentById(int id, [FromBody] CommentReplyDto commentReply, [FromHeader] int UserID, [FromHeader] string UserRole) { var comment = _context.Comments.Find(id); if (comment == null) { return(StatusCode(StatusCodes.Status404NotFound)); } if (_user.GetUserById(UserID) == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } var newCommentReply = new CommentReply() { Text = commentReply.Text, UserId = UserID, Comment = comment }; _context.CommentReplies.Add(newCommentReply); var success = _context.SaveChanges(); if (success < 1) { return(StatusCode(StatusCodes.Status400BadRequest)); } return(StatusCode(StatusCodes.Status201Created, new JsonResult(newCommentReply))); }