Пример #1
0
        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));
        }
Пример #2
0
        public async Task <IActionResult> Get(string code)
        {
            var rate = await _ratesService.GetRateAsync(code);

            if (rate == null)
            {
                return(NotFound());
            }

            return(Ok(rate));
        }