public void AddDevice(RestServiceRequest <DeviceInfo> request, RestServiceResponse <DeviceInfo> response) { if (request.Body == null || !request.Body.DeviceNumber.HasValue() || !request.Body.DeviceName.HasValue()) { throw new RequestDataInvalidException("DeviceNumber", "DeviceName"); } var retVal = _DeviceInfoRepository.AddDevice(DeviceInfoTransfer.BuildDeviceInfoSource(request.Body), DeviceSparePartTransfer.BuildDeviceSparePartSources(request.Body.DeviceSpareParts), DeviceCheckpointTransfer.BuildDeviceCheckpointSources(request.Body.DeviceCheckpoints)); if (retVal < 0) { switch (retVal) { case -1: throw new DeviceAlreadyExistedException(request.Body.DeviceNumber); default: throw new UndefinedException(retVal); } } response.Body = new DeviceInfo() { DeviceNumber = request.Body.DeviceNumber }; }
public void DeleteDevice(RestServiceRequest <DeviceInfo> request, RestServiceResponse <DeviceInfo> response) { if (!request.Body.DeviceNumber.HasValue()) { throw new RequestDataInvalidException("DeviceNumber"); } var retVal = _DeviceInfoRepository.DeleteDevice(DeviceInfoTransfer.BuildDeviceInfoSource(request.Body)); if (retVal < 0) { switch (retVal) { case -1: throw new DeviceNotFoundException(request.Body.DeviceNumber); default: throw new UndefinedException(retVal); } } }