public IActionResult DeleteDeviceType(string slug) { try { if (_bl.GetDeviceType(slug) == null) { _log.LogWarning("Not Found: DeviceType '{0}' not found", slug); return(NotFound()); } else { var dt = _bl.GetDeviceType(slug); _bl.DeleteDeviceType(dt); _bl.SaveChanges(); _log.LogInformation("DeviceType '{0}' deleted by '{1}'", dt.Name, _bl.GetCurrentUid()); } return(Ok()); } catch (SecurityException) { _log.LogWarning("Security: '{0}' tried to delete DeviceType '{1}'", _bl.GetCurrentUid(), slug); return(Unauthorized()); } catch (Exception ex) { _log.LogError("Exception: '{0}'", ex); return(StatusCode(500)); } }
public void bl_should_delete_deviceType() { var s = "delete-me"; var obj = _bl.CreateDeviceType(); obj.Slug = s; var getObj = _bl.GetDeviceType(s); Assert.NotNull(getObj); _bl.DeleteDeviceType(getObj); getObj.IsActive = false; var getDel = _bl.GetDeviceType(s); Assert.Null(getDel); }