public async Task <decimal?> CalculateExchange(decimal amount, string from, string to) { if (!Enum.IsDefined(typeof(Currencies), from.ToUpper()) || !Enum.IsDefined(typeof(Currencies), to.ToUpper())) { return(null); } var fromRate = await _ratesService.GetRateAsync(from); var toRate = await _ratesService.GetRateAsync(to); return(decimal.Round(amount * fromRate.Rate / toRate.Rate, 2, MidpointRounding.AwayFromZero)); }
public async Task <IActionResult> Get(string code) { var rate = await _ratesService.GetRateAsync(code); if (rate == null) { return(NotFound()); } return(Ok(rate)); }