public async Task <Models.DTO.Device> Create( string userId, string tenantId, RegisterDevice device, CancellationToken cancellationToken) { if (!ObjectId.TryParse(device.TypeId, out var deviceId)) { throw new ArgumentException("Invalid TypeId"); } var type = await _typeRepository.Get( deviceId, tenantId, cancellationToken) ?? throw new ArgumentException("Type not found."); var newDevice = DeviceMapper.MapToDomain( device, type, userId, tenantId); await _deviceRepository.Create( newDevice, cancellationToken); return(DeviceMapper.MapToDto(newDevice)); }
public async Task <Models.DTO.Device> Update( string id, string userId, string tenantId, UpdateDevice device, CancellationToken cancellationToken) { if (!ObjectId.TryParse(id, out var deviceId)) { throw new ArgumentException("Invalid Id, cannot cast to ObjectId."); } var deviceToUpdate = DeviceMapper.MapToDomain( deviceId, userId, tenantId, device); var updatedDevice = await _deviceRepository.Update( deviceToUpdate, cancellationToken); return(DeviceMapper.MapToDto(updatedDevice)); }