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 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); }
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); } }