public async Task <IActionResult> GetDevice([FromRoute] string SerialNumber, [FromRoute] int DeviceId) { if (!await _context.GatewayExists(SerialNumber)) { _logger.LogError($"Gateway with serial number {SerialNumber} wasn't found!"); return(NotFound($"Gateway with serial number {SerialNumber} wasn't found!")); } try { var device = await _context.GetDevice(DeviceId); if (device == null) { _logger.LogError($"Device with serial number {SerialNumber} id {DeviceId} wasn't found!"); return(NotFound($"Device with id {DeviceId} wasn't found!")); } return(Ok(device)); } catch (Exception ex) { _logger.LogError(ex.Message, ex); return(StatusCode(500, "A problem happened while handling you request.")); } }