Пример #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"));
        }