public async Task <IActionResult> DeleteDevice([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!")); } if (!await _context.DeviceExists(DeviceId)) { _logger.LogError($"Device with id {DeviceId} wasn't found!"); return(NotFound($"Device with id {DeviceId} wasn't found!")); } try { await _context.DeleteDevice(DeviceId); return(Ok()); } catch (Exception ex) { _logger.LogError(ex.Message, ex); return(StatusCode(500, "A problem happened while handling you request.")); } }