public async Task <int> SaveAsync(List <EquityApi.BalanceSheet.Response> responses) { foreach (var response in responses) { List <BalanceSheetEntity> entities = response.BalanceSheetEntityList; if (ValidateEntities(entities) != 0) { GeneralInfo generalInfo = response.GeneralInfo; _logger.LogInformation("IngestionTask ==> Symbol: {0}", generalInfo.Symbol); IngestionTask ingestionTask = IngestionTask.Create(string.Format("Balance Sheet {0}", generalInfo.ExchangeId), string.Format("Symbol: {0}", generalInfo.Symbol)); _ingestionContext.IngestionTasks.Add(ingestionTask); TGeneralInfo tGeneralInfo = _mapper.Map <TGeneralInfo>(generalInfo); tGeneralInfo.Id = Guid.NewGuid(); tGeneralInfo.IngestionTaskId = ingestionTask.IngestionTaskId; _ingestionContext.TGeneralInfo.Add(tGeneralInfo); foreach (var entity in entities) { TBalanceSheet item = _mapper.Map <TBalanceSheet>(entity); item.Id = Guid.NewGuid(); item.IngestionTaskId = ingestionTask.IngestionTaskId; _ingestionContext.TBalanceSheets.Add(item); } } } return(await _ingestionContext.SaveChangesAsync()); }
public async Task <IActionResult> CompanyFinancialsRequest(Guid id, string exchangeId) { Authentication authentication = new Authentication(_ingestionContext, _logger); TokenEntity tokenEntity = await authentication.GetAccessTokenByClientConfigId(id); if (tokenEntity != null) { string endPoint = _configuration.GetValue <string>("MorningStar:EquityApi:CompanyFinancialAvailabilityList"); EquityApi.CompanyFinancials.Request request = EquityApi.CompanyFinancials.Request.Create(tokenEntity.Token, exchangeId, "exchangeId", exchangeId); string requestUrl = endPoint.SetQueryParams(request); IngestionTask ingestionTask = IngestionTask.Create(endPoint, JsonConvert.SerializeObject(request)); _ingestionContext.IngestionTasks.Add(ingestionTask); EquityApi.CompanyFinancials.Response response = await RestClient.GetDynamicResponseAsync <EquityApi.CompanyFinancials.Response>(requestUrl); PersistenceService persistence = new PersistenceService(_ingestionContext, _mapper, _logger); int result = await persistence.SaveAsync(ingestionTask.IngestionTaskId, response); if (result > 0) { List <ChangeTable> changes = _ingestionContext.ChangeTables.FromSqlRaw("EXECUTE MergeCompanyFinancials @TaskId={0}", ingestionTask.IngestionTaskId).ToList(); _logger.LogInformation("MergeCompanyFinancials: {0}", JsonConvert.SerializeObject(changes)); } return(Ok(result)); } return(NotFound(id)); }
public async Task <int> SaveAsync(List <EquityApi.ProfitabilityRatios.Response> responses, bool isTTM = false) { foreach (var response in responses) { List <ProfitabilityEntity> entities = response.ProfitabilityEntityList; if (ValidateEntities(entities) != 0) { GeneralInfo generalInfo = response.GeneralInfo; _logger.LogInformation("IngestionTask ==> Symbol: {0}", generalInfo.Symbol); IngestionTask ingestionTask = IngestionTask.Create(string.Format("ProfitabilityRatios {0}", generalInfo.ExchangeId), string.Format("Symbol: {0}", generalInfo.Symbol)); _ingestionContext.IngestionTasks.Add(ingestionTask); TGeneralInfo tGeneralInfo = _mapper.Map <TGeneralInfo>(generalInfo); tGeneralInfo.Id = Guid.NewGuid(); tGeneralInfo.IngestionTaskId = ingestionTask.IngestionTaskId; _ingestionContext.TGeneralInfo.Add(tGeneralInfo); foreach (var entity in entities) { if (isTTM) { TProfitabilityRatioTTM item = _mapper.Map <TProfitabilityRatioTTM>(entity); item.Id = Guid.NewGuid(); item.IngestionTaskId = ingestionTask.IngestionTaskId; _ingestionContext.TProfitabilityRatioTTMs.Add(item); } else { TProfitabilityRatio item = _mapper.Map <TProfitabilityRatio>(entity); item.Id = Guid.NewGuid(); item.IngestionTaskId = ingestionTask.IngestionTaskId; _ingestionContext.TProfitabilityRatios.Add(item); } } } } return(await _ingestionContext.SaveChangesAsync()); }