public HttpResponseMessage UserDevice([FromBody] UserDeviceRequest deviceRequest) { HttpResponseMessage hrm = Request.CreateErrorResponse( HttpStatusCode.ExpectationFailed, "Unexpected Error"); using (GetEmployerConnString gecs = new GetEmployerConnString(deviceRequest.EmployerId)) { using (InsertUpdateDevice iud = new InsertUpdateDevice()) { iud.DeviceId = deviceRequest.DeviceId; int iClientAllowPushInd; if (int.TryParse(deviceRequest.ClientAllowPushInd, out iClientAllowPushInd)) { iud.ClientAllowPushInd = iClientAllowPushInd; } int iNativeAllowPushInd; if (int.TryParse(deviceRequest.NativeAllowPushInd, out iNativeAllowPushInd)) { iud.NativeAllowPushInd = iNativeAllowPushInd; } DateTime dPromptDate; if (DateTime.TryParse(deviceRequest.LastPushPromptDate, out dPromptDate)) { iud.LastPushPromptDate = dPromptDate; } iud.PostData(gecs.ConnString); if (iud.PostReturn == 1) { hrm = Request.CreateResponse(HttpStatusCode.OK); } } } return(hrm); }
/// <summary> /// Create a user device binding in Trusona between a User and a Device, referenced by their identifiers. After creation, /// the binding will be inactive, and must be explicitly activated before the User can use the Device to complete /// Trusonafications. /// </summary> /// <returns>The user device.</returns> /// <param name="trusona">The Trusona API.</param> /// <param name="userIdentifier">User identifier.</param> /// <param name="deviceIdentifier">Device identifier.</param> public static async Task <UserDevice> CreateUserDevice(this Trusona trusona, string userIdentifier, string deviceIdentifier) { UserDeviceRequest request = new UserDeviceRequest() { UserIdentifier = userIdentifier, DeviceIdentifier = deviceIdentifier }; try { var response = await trusona.UserDeviceService.CreateUserDeviceAsync(request); return(trusona.mapper.Map <UserDevice>(response)); } catch (TrusonaServiceException ex) { HandleServiceException(ex, (httpStatus, requestId) => { switch (httpStatus) { case HttpStatusCode.Conflict: throw new DeviceAlreadyBoundException("A different user has already been bound to this device."); case (HttpStatusCode)424: throw new DeviceNotFoundException("The device you are attempting to bind to a user does not exist. The device will need to be re-registered with Trusona before attempting to bind it again."); default: DefaultErrorHandler(httpStatus, requestId); break; } }); throw ex; } }
public Task <UserDeviceResponse> CreateUserDeviceAsync(UserDeviceRequest request) { return(Post <UserDeviceResponse>( resource: "/api/v2/user_devices", content: request, credentialProvider: _credentialProvider )); }
public void CreateUserDevice_should_return_a_user_device_response() { //given var userDevice = new UserDeviceRequest() { }; SetupMock(); //when var res = sut.CreateUserDevice(userDevice); //then res.Should() .BeOfType <UserDeviceResponse>(); }
public UserDeviceResponse CreateUserDevice(UserDeviceRequest request) { return(BlockAsyncForResult( CreateUserDeviceAsync(request) )); }