public IActionResult DeleteDevice(int id) { try { if (!_bl.DeviceExists(id)) { _log.LogWarning("Not Found: Device '{0}' not found", id); return(NotFound()); } var d = _bl.GetSingleDevice(id); _bl.DeleteDevice(d); _bl.SaveChanges(); _log.LogInformation("Device '{0}({1})' deleted by '{2}'", d.InvNum, d.Name, User.Identity.Name); return(Ok(d)); } catch (SecurityException) { _log.LogWarning("Security: '{0}' tried to delete Device '{1}'", _bl.GetCurrentUid(), id); return(Unauthorized()); } catch (Exception ex) { _log.LogError("Exception: {0}", ex); return(StatusCode(500)); } }
public void bl_should_return_if_device_exists() { var obj = _bl.CreateDevice(); obj.DeviceId = 87; obj.InvNum = Guid.NewGuid().ToString(); var doesExist = _bl.DeviceExists(obj.DeviceId); Assert.True(doesExist); }