/// <inheritdoc /> public async Task <Person> GetPerson(string ssn) { Person person = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Person)); Uri endpointUrl = new Uri($"{_generalSettings.GetApiBaseUrl()}persons"); using (HttpClient client = HttpApiHelper.GetApiClient()) { string ssnData = JsonConvert.SerializeObject(ssn); HttpResponseMessage response = await client.PostAsync(endpointUrl, new StringContent(ssnData, Encoding.UTF8, "application/json")); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream stream = await response.Content.ReadAsStreamAsync(); person = serializer.ReadObject(stream) as Person; } else { _logger.LogError($"Getting person with ssn {ssn} failed with statuscode {response.StatusCode}"); } } return(person); }
/// <inheritdoc /> public async Task <UserProfile> GetUser(int userId) { UserProfile user = null; Uri endpointUrl = new Uri($"{_generalSettings.GetApiBaseUrl()}users/{userId}"); HttpResponseMessage response = await _client.GetAsync(endpointUrl); if (response.StatusCode == System.Net.HttpStatusCode.OK) { string content = await response.Content.ReadAsStringAsync(); user = Newtonsoft.Json.JsonConvert.DeserializeObject <UserProfile>(content); user.ProfileSettingPreference.Language = MapLanguageString(user.ProfileSettingPreference.Language); } else { _logger.LogError($"Getting user with user id {userId} failed with statuscode {response.StatusCode}"); } return(user); }
/// <inheritdoc /> public async Task <UserProfile> GetUser(int userId) { UserProfile user = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(UserProfile)); Uri endpointUrl = new Uri($"{_generalSettings.GetApiBaseUrl()}users/{userId}"); HttpResponseMessage response = await _client.GetAsync(endpointUrl); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream stream = await response.Content.ReadAsStreamAsync(); user = serializer.ReadObject(stream) as UserProfile; } else { _logger.LogError($"Getting user with user id {userId} failed with statuscode {response.StatusCode}"); } return(user); }
/// <inheritdoc /> public async Task <Party> GetParty(int partyId) { Party party = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Party)); Uri endpointUrl = new Uri($"{_generalSettings.GetApiBaseUrl()}parties/{partyId}"); using (HttpClient client = HttpApiHelper.GetApiClient()) { HttpResponseMessage response = await client.GetAsync(endpointUrl); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream stream = await response.Content.ReadAsStreamAsync(); party = serializer.ReadObject(stream) as Party; } else { _logger.LogError($"Getting party with party Id {partyId} failed with statuscode {response.StatusCode}"); } } return(party); }
/// <inheritdoc /> public async Task <Organization> GetOrganization(string orgNr) { Organization org = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Organization)); Uri endpointUrl = new Uri($"{_generalSettings.GetApiBaseUrl()}/organizations/{orgNr}"); using (HttpClient client = HttpApiHelper.GetApiClient()) { HttpResponseMessage response = await client.GetAsync(endpointUrl); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream stream = await response.Content.ReadAsStreamAsync(); org = serializer.ReadObject(stream) as Organization; } else { _logger.LogError($"Getting org with org nr {orgNr} failed with statuscode {response.StatusCode}"); } } return(org); }