public IList <ApplicationModel> GetApplicationsByClientId(GetApplicationByClientIdMqQuery command)
 {
     try
     {
         return(_db.Query <ApplicationModel>("GetApplicationByClientId", new { command.ClientId, command.DepartmentAddress }, commandType: CommandType.StoredProcedure).ToList());
     }
     catch (SqlException e)
     {
         _logger.LogError($"Error in database: {e.Message}");
         throw;
     }
 }
        public IActionResult GetApplicationStatus(GetApplicationByClientIdQuery command)
        {
            _logger.LogInformation($"Processing request: {JsonConvert.SerializeObject(command)}");

            if (string.IsNullOrEmpty(command.ClientId) || string.IsNullOrEmpty(command.DepartmentAddress))
            {
                _logger.LogError("Request is invalid");
                return(NotFound());
            }

            _channel.QueueDeclare(queue: GetByClientIdQueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);

            var mqCommand = new GetApplicationByClientIdMqQuery()
            {
                ClientId          = command.ClientId,
                DepartmentAddress = command.DepartmentAddress,
                ClientIp          = HttpContext.Connection.RemoteIpAddress.ToString(),
            };

            string message;

            try
            {
                message = JsonConvert.SerializeObject(mqCommand);
                var body = Encoding.UTF8.GetBytes(message);
                _channel.BasicPublish(exchange: "",
                                      routingKey: GetByClientIdQueueName,
                                      basicProperties: _props,
                                      body: body);
            }
            catch (Exception e)
            {
                _logger.LogError($"Error from message queue: {e.Message}");
                return(StatusCode((int)HttpStatusCode.BadGateway));
            }
            _logger.LogInformation($"Sent message: {message}");

            _channel.BasicConsume(
                consumer: _consumer,
                queue: _replyQueueName,
                autoAck: true);

            var response = _respQueue.Take();

            _logger.LogInformation($"Received message from server: {response}");
            return(Ok(response));
        }