public async Task <IActionResult> GetAllRates(
            [FromRoute] string baseSymbol,
            [FromServices] IExchangeRateService exchangeRateService,
            [FromServices] IValidationService validationService)
        {
            if (!validationService.IsProperBaseSymbol(baseSymbol))
            {
                return(BadRequest($"Incorrect Base Symbol: {baseSymbol}. Only EUR is supported"));
            }

            try
            {
                var allRates = await exchangeRateService.GetAllRates(baseSymbol);

                return(new JsonResult(allRates));
            }
            catch (ExchangeRateException exception)
            {
                return(BadRequest(new ErrorModel($"{exception.Message}. {baseSymbol} is not supported. Only EUR is allowed as base currency")));
            }
        }
Exemplo n.º 2
0
        public async Task <bool> DoesSuchASymbolExist(string symbol)
        {
            var symbols = await ExchangeRateService.GetAllRates("EUR");

            return(symbols.Any(symbolPair => symbolPair.Key.ToLower() == symbol.ToLower()));
        }