예제 #1
0
 public IActionResult Delete(int id)
 {
     try
     {
         _commentManager.DeleteComment(id);
         return(Ok());
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
 }
예제 #2
0
        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 }));
        }
예제 #3
0
        public async Task <IActionResult> ConfirmDeleteComment(CommentViewModel comment)
        {
            await _commentManager.DeleteComment(comment.Id);

            return(RedirectToAction("Index", "Home"));
        }