private Price(decimal amount, string currencyCode, IcurrencyLookup currencyLookup) : base(amount, currencyCode, currencyLookup) { if (amount < 0) { throw new ArgumentException("Price cannot be negative", nameof(amount)); } }
protected Money(decimal amount, string currencyCode, IcurrencyLookup currencyLookup) { if (string.IsNullOrEmpty(currencyCode)) { throw new ArgumentNullException(nameof(currencyCode), "Currency code must be specified"); } CurrencyDetails currency = currencyLookup.FindCurrency(currencyCode); if (!currency.InUse) { throw new ArgumentException($"Currency {currencyCode} is not valid"); } if (decimal.Round(amount, currency.DecimalPlaces) != amount) { throw new ArgumentOutOfRangeException(nameof(amount), $"Amount in {currencyCode} cannot have more than {currency.DecimalPlaces} decimals"); } Amount = amount; Currency = currency; }
public static Money FromString(string amount, string currency, IcurrencyLookup currencyLookup) => new Money(decimal.Parse(amount), currency, currencyLookup);
public static Money FromDecimal(decimal amount, string currency, IcurrencyLookup currencyLookup) => new Money(amount, currency, currencyLookup);
public new static Price FromDecimal(decimal amount, string currency, IcurrencyLookup currencyLookup) => new Price(amount, currency, currencyLookup);
public ClassfiedAdApplicationService(IClassifiedAdRepository repository, IUnitOfWork unitOfWork, IcurrencyLookup currencyLookup) { _currencyLookup = currencyLookup; _unitOfWork = unitOfWork; _repository = repository; }