Example #1
0
        public IActionResult CalculateTotal([FromBody] CalculateTotalModel model)
        {
            if (model.Roster.Count == 0)
            {
                return(Ok(0));
            }

            var usd = model.Roster.Aggregate(
                0d,
                (total, item) => total + _currencyConverter.ConvertToUSD(item.CurrencyAbbrv, item.Value));
            var convertedTotal = _currencyConverter.ConvertFromUSD(model.TargetCurrencyAbbrv, usd);

            return(Ok(Math.Round(convertedTotal, 2)));
        }