public virtual async Task <ActionResult> Post([FromBody] IList <T1> newRecords) { if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status422UnprocessableEntity, "Can't processable Entities")); } try { var recordsToSave = _mapper.Map <List <T> >(newRecords); for (int i = 0; i < recordsToSave.Count; i++) { IAPPDoc curRcd = recordsToSave[i]; recordsToSave[i] = (T)DBValuesSetup.SetAppDocValues(curRcd); } await _appRepository.AddManyAsync(recordsToSave); await DBValuesSetup.CreateIndex <T>(_appRepository); } catch (Exception ex) { _logger.LogError($"Error occurred while performing Post operation; error:\n {ex.Message} "); return(StatusCode(StatusCodes.Status500InternalServerError, "Something went wrong while performing Post operation")); } return(Ok(true)); }
private List <DailyPriceDB> ConvertPriceJsonToObjects(string tdaResponse) { var jobjs = JObject.Parse(tdaResponse).SelectTokens(@"$.*"); var currentPricesDB = new List <DailyPriceDB>(); foreach (var dpDB in from jobj in jobjs let dpDB = mapper.Map <DailyPriceDB>(jobj.ToObject <DailyPrice>()) select dpDB) { var saveObj = (DailyPriceDB)DBValuesSetup.SetAppDocValues(dpDB); currentPricesDB.Add(saveObj); } return(currentPricesDB); }
private async Task UpdateRunDateAsync() { await appRepository.DeleteOneAsync <RunDateSaveDB>(r => r.Symbol.Equals(SecAnalKey)); var currentRunDateSave = new RunDateSave { ProcessName = SecAnalKey, LastRunTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }; var currentRunDateSaveDb = mapper.Map <RunDateSaveDB>(currentRunDateSave); currentRunDateSaveDb = (RunDateSaveDB)DBValuesSetup.SetAppDocValues(currentRunDateSaveDb); await appRepository.AddOneAsync <RunDateSaveDB>(currentRunDateSaveDb); await DBValuesSetup.CreateIndex <RunDateSaveDB>(appRepository); }
private async Task <bool> SaveSecurityAnalyses() { if (SecurityAnalyses == null || SecurityAnalyses.Count == 0) { return(false); } var drh = client.DefaultRequestHeaders; if (!drh.Contains(@"x-api-key")) { client.DefaultRequestHeaders.Add(@"x-api-key", IsrKey); } //Don't want anything. Delete all. var getRunDate = DBValuesSetup.ComputeRunDate().AddMonths(1); var delUrlStr = $"{securityAnalysisAPI}/{getRunDate.Year}/{getRunDate.Month}/{getRunDate.Day}"; await client.DeleteAsync(delUrlStr); const int stepCount = 30; for (int i = 0; i < SecurityAnalyses.Count; i += stepCount) { var selectedRcds = SecurityAnalyses.Skip(i).Take(stepCount); var json = JsonConvert.SerializeObject(selectedRcds); var data = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(securityAnalysisAPI, data); if (!response.IsSuccessStatusCode) { logger.LogError($"Error Saving security analyses: {response.ReasonPhrase}"); return(false); } } return(true); //var securityAnalysesDbLst = mapper.Map<List<SecurityAnalysisDB>>(SecurityAnalyses); //for (int i = 0; i < securityAnalysesDbLst.Count; i++) //{ //securityAnalysesDbLst[i] = (SecurityAnalysisDB)DBValuesSetup.SetAppDocValues(securityAnalysesDbLst[i]); //} //await appRepository.DeleteManyAsync<SecurityAnalysisDB>(r => r.ComputeDate != securityAnalysesDbLst[0].ComputeDate); //await appRepository.AddManyAsync(securityAnalysesDbLst); //await DBValuesSetup.CreateIndex<SecurityAnalysisDB>(appRepository); }
public async Task <bool> StoreValuesToDb() { if (slickChartFirmNames == null || slickChartFirmNames.Count == 0) { return(false); } var scfnDB = mapper.Map <List <SlickChartFirmNamesDB> >(slickChartFirmNames); for (int i = 0; i < scfnDB.Count; i++) { IAPPDoc aPPDoc = scfnDB[i]; scfnDB[i] = (SlickChartFirmNamesDB)DBValuesSetup.SetAppDocValues(aPPDoc); } var deleteCount = await appRepository.DeleteManyAsync <SlickChartFirmNamesDB>(r => r.ComputeDate <= scfnDB[0].ComputeDate); await appRepository.AddManyAsync(scfnDB); await DBValuesSetup.CreateIndex <SlickChartFirmNamesDB>(appRepository); return(true); }
private async Task SaveCurrentRunDate() { try { await appRepository.DeleteOneAsync <RunDateSaveDB>(r => r.Symbol.Equals(PricingDataKey)); var currentRunDateSave = new RunDateSave { ProcessName = PricingDataKey, LastRunTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }; var currentRunDateSaveDb = mapper.Map <RunDateSaveDB>(currentRunDateSave); currentRunDateSaveDb = (RunDateSaveDB)DBValuesSetup.SetAppDocValues(currentRunDateSaveDb); await appRepository.AddOneAsync <RunDateSaveDB>(currentRunDateSaveDb); await DBValuesSetup.CreateIndex <RunDateSaveDB>(appRepository); } catch (Exception ex) { logger.LogError($"Error while updating Run Date for {PricingDataKey}"); logger.LogError($"Error details \n\t{ex.Message}"); } }
public async Task <bool> GetPricingData() { try { if (securityList == null || securityList.Count == 0) { return(false); } var queryTickers = string.Join(',', securityList); string urlStr = quotesAPI.Replace(@"{tickersToUse}", queryTickers) .Replace(@"{apiKey}", apiKey); string tdaResponse = await client.GetStringAsync(urlStr); if (tdaResponse.IsNullOrWhiteSpace()) { return(false); } //logger.LogDebug(tdaResponse); List <DailyPriceDB> currentPricesDB = ConvertPriceJsonToObjects(tdaResponse); var listOfSymbols = from a in currentPricesDB select a.Symbol; var recordsDeleted = await appRepository.DeleteManyAsync <DailyPriceDB>(r => listOfSymbols.Contains(r.Symbol)); await appRepository.AddManyAsync(currentPricesDB); await DBValuesSetup.CreateIndex <DailyPriceDB>(appRepository); return(true); } catch (Exception ex) { logger.LogError("Issues getting data from TDA"); logger.LogError($"Error details \n\t{ex.Message}"); return(false); } }