public IActionResult Delete(int id) { try { _commentManager.DeleteComment(id); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex)); } }
public IActionResult DeleteComment(int commentId) { var currentUserId = HttpContext.User .Claims? .FirstOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier)? .Value ?? string.Empty; var commentOwnerId = _commentManager.GetCommentOwner(commentId); if (currentUserId != commentOwnerId) { return(StatusCode(403, new { message = "Invalid user id" })); } var(success, message) = _commentManager.DeleteComment(commentId); if (success) { return(Ok(new { message })); } return(StatusCode(500, new { message })); }
public async Task <IActionResult> ConfirmDeleteComment(CommentViewModel comment) { await _commentManager.DeleteComment(comment.Id); return(RedirectToAction("Index", "Home")); }