public async Task <MaterialStub> CreateMaterialStubAsync(string type, string code, long firm, string language) { var uri = _baseUri + $"/api/{_apiVersion}/{type}/{code}/session?firm={firm}&languages={language}"; long materialsStubId = 0; try { using (var response = await _httpClient.PostAsync(uri, new StringContent(String.Empty, Encoding.UTF8, "application/json"))) { var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { _logger.Error("Unsuccessfull response with code {code} and content {content}", response.StatusCode, content); response.EnsureSuccessStatusCode(); } var stub = MaterialStub.FromJson(content).First(); materialsStubId = stub.Id; return(content != null ? stub : null); } } catch (Exception ex) { _logger.Error(ex, "Exception occured while creating AM template for firmId: {firmId}, stubId: {stubId}", firm, materialsStubId); throw; } }
private async Task <MaterialStub[]> GetMaterialAsync(long id) { var uri = _baseUri + $"/api/{_apiVersion}/am/{id}"; using (var response = await _retryPolicy.ExecuteAsync(() => _httpClient.GetAsync(uri))) { var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { _logger.Error("Unsuccessfull response with code {code} and content {content}; Material id: {id}", response.StatusCode, content, id); response.EnsureSuccessStatusCode(); } return(content != null?MaterialStub.FromJson(content) : null); } }