public ExchangeRate CalculateFromNationalBankRate(string foreignCurrencyISOName, decimal rate, DateTime timestampUtc) { Argument.NotEmpty(foreignCurrencyISOName, "foreignCurrencyISOName"); Argument.Satisfies(foreignCurrencyISOName, x => x != _settings.NationalCurrency); Argument.Satisfies(rate, x => x > 0, "rate"); var conversionRate = new ConversionRate(new CurrencyConversion(_settings.NationalCurrency, foreignCurrencyISOName), rate); return(CalculateFromConversionRate(conversionRate, timestampUtc, _roundingSettings.GetRounding(foreignCurrencyISOName))); }
public ExchangeRate CalculateFromConversionRate(ConversionRate conversionRate, DateTime timstampUtc, Rounding rounding) { Argument.NotNull(conversionRate, "conversionRate"); var baseCurrency = _currencyRepository.Find(conversionRate.Conversion.From); if (baseCurrency == null) { var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.From); throw new InvalidOperationException(message); } var foreignCurrency = _currencyRepository.Find(conversionRate.Conversion.To); if (foreignCurrency == null) { var message = string.Format("Can't find currency [{0}] in the database.", conversionRate.Conversion.To); throw new InvalidOperationException(message); } var buyRate = MoneyMath.Round(conversionRate.Rate * (decimal)Randomizer.FromRange(_settings.BuyRateCoefficientRange), rounding); var sellRate = MoneyMath.Round(conversionRate.Rate * (decimal)Randomizer.FromRange(_settings.SellRateCoefficientRange), rounding); return(ExchangeRate.Create(baseCurrency, foreignCurrency, buyRate, sellRate, timstampUtc)); }