Beispiel #1
0
        public async Task <IActionResult> GetExcRateInfo(ExchangeRateRequest exchangeRateRequest)
        {
            Dictionary <string, Rates> ratesThatIsNeeded = new Dictionary <string, Rates>();
            var datePeriod = _exchangeRateService.GetDatePeriod(exchangeRateRequest.ListOfDates);

            string url = $"{endpoint}history?base={exchangeRateRequest.BaseCurrency}&start_at={datePeriod.startDate}&end_at={datePeriod.endDate}";

            var request = new HttpRequestMessage(HttpMethod.Get, url);
            var client  = _httpClientFactory.CreateClient();
            HttpResponseMessage responseJson = await client.SendAsync(request);

            ExchangeRateList = await responseJson.Content.ReadFromJsonAsync <ExchageRateListModel>();

            foreach (var i in ExchangeRateList.rates)
            {
                foreach (var x in exchangeRateRequest.ListOfDates)
                {
                    if (i.Key == x)
                    {
                        ratesThatIsNeeded.Add(i.Key, i.Value);
                    }
                }
            }

            var response = _exchangeRateService.GetData(ratesThatIsNeeded, exchangeRateRequest.TargetCurrnecy);

            //var a = await response.Content.ReadFromJsonAsync<ExchangeRateModel>();

            string resp = $"A min exchange rate of {response.MinExchangeRate} on {response.MinExchangeRateDate}, a max exchange rate of {response.MaxExchangeRate} on {response.MaxExchangeRateDate} and average exhange rate was {response.AverageExchangeRate}";

            return(Ok(resp));
        }