Example #1
0
        public void ConvertMoney(int id, string fromCurrency, string toCurrency, decimal amount)
        {
            var user = Users.FirstOrDefault(x => x.Id == id);

            if (user == null)
            {
                throw new NullReferenceException("User was not found");
            }

            try
            {
                if (user.Wallet[fromCurrency.ToUpper()] < amount)
                {
                    throw new NullReferenceException("You don't have enough money!");
                }

                var exchangeRate = _currencyConverterService.GetExchangeRate(fromCurrency, toCurrency, amount);
                user.Wallet[fromCurrency.ToUpper()] -= amount;
                user.Wallet[toCurrency.ToUpper()]   += exchangeRate;
            }
            catch
            {
                throw new NullReferenceException("Сonversion failed");
            }
        }