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