Esempio n. 1
0
        protected Money(decimal amount, string currencyCode, ICurrencyLookup currencyLookup)
        {
            if (string.IsNullOrEmpty(currencyCode))
            {
                throw new ArgumentException("Currency code must be specified", nameof(currencyCode));
            }
            var currency = currencyLookup.FindCurrency(currencyCode);

            if (!currency.InUse)
            {
                throw new ArgumentException($"Currency {currencyCode} is not valid");
            }

            if (decimal.Round(amount, currency.DecimalPlaces) != amount)
            {
                throw new ArgumentException($"Amount cannot have more than {currency.DecimalPlaces} decimals", nameof(amount));
            }
            Amount   = amount;
            Currency = currency;
        }
Esempio n. 2
0
 protected Money(decimal amount, CurrencyDetails currency)
 {
     Amount   = amount;
     Currency = currency;
 }