// Summary: // Get the list of currencies supported by the data repository. // // Return: // ShowExchangeRateDto // An instance to ShowExchangeRateDto public async Task <ListCurrencyDto> GetAllAvailableCurrencies() { ShowExchangeRateDto showExchangeRateDto = await GetAllConversionRatesByCurrency("EUR"); Array currencyList = showExchangeRateDto.Rates.Keys.ToArray(); return(new ListCurrencyDto { Currencies = (string[])currencyList }); }
// Summary: // Get conversion rates for historic days. // // Parameters: // DateTime: // History datetime // Return: // ShowExchangeRateDto // An instance to ShowExchangeRateDto public async Task <ShowExchangeRateDto> GetHistoricRateByDate(DateTime dateval) { HistoricExchangeRates historicExchangeRates = await _currencyRepository.GetConversionRatesByDate(dateval); ShowExchangeRateDto showExchangeRateDto = new ShowExchangeRateDto() { Base = historicExchangeRates.Base, Timestamp = historicExchangeRates.Timestamp, Date = historicExchangeRates.Date, Rates = historicExchangeRates.Rates }; return(showExchangeRateDto); }
public async Task <ActionResult <ShowExchangeRateDto> > GetRatesByCurrency(string currencyCode) { try { ShowExchangeRateDto showExchangeRateDto = await this._currencyService.GetAllConversionRatesByCurrency(currencyCode); if (showExchangeRateDto.Base is null) { // need to log return(NotFound()); } return(Ok(showExchangeRateDto)); } catch (Exception) { // need to log return(NotFound()); } }
public async Task <ActionResult <ShowExchangeRateDto> > GetHistoricRateByDate(int days) { try { DateTime currentDate = DateTime.Now; ShowExchangeRateDto showExchangeRateDto = await _currencyService.GetHistoricRateByDate(currentDate.AddDays(-days)); if (showExchangeRateDto.Base is null) { // need to log return(NotFound()); } return(Ok(showExchangeRateDto)); } catch (Exception) { // need to log return(NotFound()); } }
// Summary: // It internally converts the base currency to the targer currency since API only supports EUR // // Parameters: // latestExchangeRates: // An instance to LatestExchangeRates // string: // Currency code. // Return: // showExchangeRateDto // An instance to ShowExchangeRateDto private ShowExchangeRateDto ConvertAsBaseCurrency(LatestExchangeRates latestExchangeRates, string currencyCode) { ShowExchangeRateDto convertedRates = new ShowExchangeRateDto() { Base = currencyCode, Timestamp = latestExchangeRates.Timestamp, Date = latestExchangeRates.Date, Rates = new Dictionary <string, float>() }; if (latestExchangeRates.Base == currencyCode) { convertedRates.Rates = latestExchangeRates.Rates; return(convertedRates); } foreach (KeyValuePair <string, float> entry in latestExchangeRates.Rates.ToList()) { ShowConversionDto showConversionDto = new ShowConversionDto(currencyCode, entry.Key, 0); convertedRates.Rates.Add(entry.Key, CalculateExchangeRateValue(showConversionDto, latestExchangeRates)); } return(convertedRates); }