public async Task <DcfDto> GetDcf(string stock) { DcfDto result = null; try { _logger.WriteInformation("Getting DCF List"); using (var httpClient = new HttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod("GET"), _dcfUrl + stock)) { request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1"); _logger.WriteInformation($"Getting {stock} DCF"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <DcfDto>(jsonString); } } } } catch (Exception ex) { _logger.WriteError("Error calling DCF API", ex); } _logger.WriteInformation("Received DCF"); return(result); }
public void AddDcf(DcfDto dto) { try { //_context.Dcfs.Add(dto); } catch (Exception ex) { ex.Data.Add(dto.Id, dto); _logger.WriteError("Error saving DCF list to DB", ex); } }