Exemplo n.º 1
0
        public static ExchangeRateOutputModel GetExchangeRateStatistics(string startDate, string endDate, string baseCurrency, string targetCurrency)
        {
            int retryCounter = 0;

retry:
            try
            {
                ExchangeRateHistoryServiceResponseModel exchangeRateHistory = ExchangeRateService.GetExchangeRateHistory(startDate, endDate, baseCurrency,
                                                                                                                         targetCurrency).Result;

                List <ExchangeRateDateModel> exchangeRateDateModelList = exchangeRateHistory.rates.Select(x => new ExchangeRateDateModel
                {
                    Date = x.Key,
                    Rate = x.Value.ContainsKey(targetCurrency.ToUpper()) ?
                           x.Value.Where(y => y.Key.Equals(targetCurrency, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().Value : 0
                }).OrderBy(z => z.Rate).ToList();

                return(GetCurrencyStatisticsDataLogic(exchangeRateDateModelList));
            }
            catch (Exception exService)
            {
                retryCounter++;
                if (retryCounter <= 2)
                {
                    goto retry;
                }
                else
                {
                    throw exService;
                }
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> GetExchangeRateHistory(DateTime startDate, DateTime endDate, string baseCurrency, string targetCurrency)

        {
            var _service = new ExchangeRateService();

            var res = await _service.GetExchangeRateHistory(startDate, endDate, baseCurrency, targetCurrency);

            return(Ok(res));
        }