Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
        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);
            }
        }