Beispiel #1
0
        public async Task <CommandReturn> GetHistorialRates(GetHistorialRatesCommand command)
        {
            string methodName = nameof(GetHistorialRates);

            if (!command.IsValid())
            {
                var errors = command.Errors();
                _logger.Error(errors, methodName);

                return(new CommandReturn(false, errors, ""));
            }

            try
            {
                var objList        = new List <object>();
                var actualDate     = DateTime.Now;
                var monthsQuantity = ((actualDate.Year - command.InitialDate.Year) * 12) + actualDate.Month - command.InitialDate.Month;

                await AddCoins(command.CoinSymbol, command.InitialDate, objList, monthsQuantity);

                CoinLoreResponse responseApiObj = await GetCoinRecord(command.CoinSymbol, actualDate);

                AddCoin(command.CoinSymbol, objList, responseApiObj);


                _logger.Info(objList, methodName);
                return(new CommandReturn(true, "Consulta realizada com sucesso!", objList));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, methodName);
                return(new CommandReturn(false, "Erro na consulta, favor tentar novamente"));
            }
        }
Beispiel #2
0
        private async Task AddCoins(string coinSymbol, DateTime initialDate, List <object> objList, int monthsQuantity)
        {
            for (int i = 0; i < monthsQuantity; i++)
            {
                CoinLoreResponse responseApiObj = await GetCoinRecord(coinSymbol, initialDate);

                AddCoin(coinSymbol, objList, responseApiObj);

                initialDate = initialDate.AddMonths(1);
            }
        }
Beispiel #3
0
        private static void AddCoin(string coinSymbol, List <object> objList, CoinLoreResponse responseApiObj)
        {
            var jObj      = (JObject)responseApiObj.rates;
            var coinValue = jObj.Value <string>(coinSymbol);

            var resultObj = new
            {
                responseApiObj.date,
                coinValue,
                coinSearched = coinSymbol
            };

            objList.Add(resultObj);
        }