예제 #1
0
        public async Task <IActionResult> GetRatesForCurrencies()
        {
            string exchangeRatesData;

            try
            {
                exchangeRatesData = await _exchange.GetExchangeRatesData(_apiConnections.UriString,
                                                                         _apiConnections.RequestUriAllRates);
            }
            catch (StatusCodeException e)
            {
                var codeNumber = e.CodeNumber;
                return(StatusCode(codeNumber, StatusCodeResponses.GetResponseMessage(codeNumber)));
            }
            var          exchangeRates = _exchange.GetExchangeRates(exchangeRatesData);
            const string message       = "Current exchange rates (currency to PLN):\n";

            var actualRates = _exchangeHelper.GetActualRates(exchangeRates);
            var codes       = JsonConvert.SerializeObject(actualRates);

            return(Ok(message + codes));
        }