Ejemplo n.º 1
0
        public static ICurrencyAmount ToNewCurrency(ICurrencyAmount amountInfo, string currencyCode, double rate)
        {
            var newAmount           = amountInfo.Amount * (decimal)rate;
            var convertedAmountInfo = new CurrencyAmount(currencyCode, newAmount);

            return(convertedAmountInfo);
        }
Ejemplo n.º 2
0
 public Expense(ICurrencyAmount amount, DateTimeOffset date, string category, string destination)
 {
     Amount      = amount;
     Date        = date;
     Category    = category;
     Destination = destination;
 }
Ejemplo n.º 3
0
 public Transfer(ICurrencyAmount amount, DateTimeOffset date, string destination, string message)
 {
     Amount      = amount;
     Date        = date;
     Destination = destination;
     Message     = message;
 }
Ejemplo n.º 4
0
        public async Task <ICurrencyAmount> ConvertCurrencyAsync(ICurrencyAmount amount, string currencyCode)
        {
            var actualExchangeRates = await GetExchangeRatesFromMemoryAsync();

            var exchangeRate = (decimal)(actualExchangeRates.Rates[currencyCode] / actualExchangeRates.Rates[amount.CurrencyCode]);

            return(new CurrencyAmount(currencyCode, amount.Amount * exchangeRate));
        }
Ejemplo n.º 5
0
        public async Task <ICurrencyAmount> ConvertCurrencyAsync(ICurrencyAmount amountInfo, string currencyCode)
        {
            var ratesInfo = await _memoryCache.GetOrCreateAsync <RatesInfo>("rates_info", entry => GetRatesAsync());

            if (ratesInfo.Rates.TryGetValue(currencyCode, out var rate))
            {
                return(ToNewCurrency(amountInfo, currencyCode, rate));
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(currencyCode), $"Немогу получить курс для {currencyCode}");
            }
        }
Ejemplo n.º 6
0
 public Income(ICurrencyAmount amount, DateTimeOffset date, string source)
 {
     Amount = amount;
     Date   = date;
     Source = source;
 }
Ejemplo n.º 7
0
 public ICurrencyAmount ConvertCurrency(ICurrencyAmount amount, string currencyCode)
 {
     return(ConvertCurrencyAsync(amount, currencyCode).Result);
 }
        ICurrencyAmount ICurrencyConverter.ConvertCurrency(ICurrencyAmount amount, string currencyCode)
        {
            decimal convertedAmount = amount.Amount * GetExchangeRateValue(amount.CurrencyCode, currencyCode);

            return(new CurrencyAmount(currencyCode, convertedAmount));
        }
 public ICurrencyAmount ConvertCurrency(ICurrencyAmount amount, string currencyCode)
 {
     return(new CurrencyAmount(currencyCode, amount.Amount));
 }