Ejemplo n.º 1
0
        public IActionResult Delete(string commentUuid)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (!SecureGuid.VerifyGuid(commentUuid, out _))
            {
                _logger.LogInformation("Comment UUID is invalid.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }

            var comment = new Comment
            {
                Uuid = commentUuid
            };

            if (_database.DeleteComment(comment, user))
            {
                _activityLogger.LogDeleteComment(Request.HttpContext.Connection.RemoteIpAddress, user, comment);
                return(Ok());
            }

            _logger.LogInformation("Database failed to delete comment.");
            _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                   $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
            _authHandler.TerminateSession(user);
            return(BadRequest());
        }