public async Task<UserInformation> AddUserDevice(UserDevice newUserDevice, ICredentialRetrieverService credentialRetrieverService) { newUserDevice.CheckIfNull ("newUserDevice"); credentialRetrieverService.CheckIfNull ("credentialRetrieverService"); using ( var authenticatedClient = new AuthenticatedHttpClient( this.baseUrl, credentialRetrieverService.GetNetworkCredential())) { try { var content = new StringContent(this.serializer.Serialize(newUserDevice), Encoding.UTF8, ApplicationJson); var response = await authenticatedClient.Client.PostAsync(PostUserDevice, content); response.EnsureSuccessStatusCode(); var userInformation = await response.Content.ReadAsStringAsync(); return this.serializer.Deserialize<UserInformation>(userInformation); } catch (HttpRequestException e) { var message = e.Message; MvxTrace.Trace(() => message); } } return null; }
public async Task<UserInformation> DeleteUserDevice(UserDevice existingUserDevice, ICredentialRetrieverService credentialRetrieverService) { existingUserDevice.CheckIfNull("existingUserDevice"); credentialRetrieverService.CheckIfNull("credentialRetrieverService"); using ( var authenticatedClient = new AuthenticatedHttpClient( this.baseUrl, credentialRetrieverService.GetNetworkCredential())) { try { var deleteUrl = string.Format(DeleteUserDeviceTemplate, existingUserDevice.Id); var response = await authenticatedClient.Client.DeleteAsync(deleteUrl); response.EnsureSuccessStatusCode(); var userInformation = await response.Content.ReadAsStringAsync(); return this.serializer.Deserialize<UserInformation>(userInformation); } catch (HttpRequestException e) { var message = e.Message; MvxTrace.Trace(() => message); } } return null; }