protected Money(decimal amount, string currencyCode, ICurrencyLookup currencyLookup) { if (amount == default) { throw new ArgumentException("Value must be specified", nameof(amount)); } if (currencyCode == default) { throw new ArgumentException("currency Code must be specified", nameof(currencyCode)); } var currency = currencyLookup.FindCurrency(currencyCode); if (currency == Currency.None) { throw new ArgumentException($"Invalid currency code: {currencyCode}"); } if (Math.Round(amount, currency.DecimalPlaces) != amount) { throw new ArgumentException($"amount must have no more than {currency.DecimalPlaces} decimals for currency {currency.CurrencyCode}", nameof(amount)); } Amount = amount; CurrencyCode = currency.CurrencyCode; }
public 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"); } 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 ArgumentOutOfRangeException( nameof(amount), $"Amount in {currencyCode} cannot have more than {currency.DecimalPlaces} decimals"); } Amount = amount; Currency = currency; }
public ClassifiedAdsApplicationService( IAggregateStore store, ICurrencyLookup currencyLookup ) { _currencyLookup = currencyLookup; _store = store; }
public ClassifiedAdsApplicationService(IClassifiedAdRepository repository, IUnitOfWork unitOfWork, ICurrencyLookup currencyLookup) { _repository = repository; _currencyLookup = currencyLookup; _unitOfWork = unitOfWork; }
public ClassifiedAdsApplicationService( IClassifiedAdRepository repository, ICurrencyLookup currencyLookup) { _repository = repository; _currencyLookup = currencyLookup; }
Price(decimal value, string currencyCode, ICurrencyLookup currencyLookup) : base(value, currencyCode, currencyLookup) { if (value < 0) { throw new ArgumentException("Price cannot be negative", nameof(value)); } }
public ClassifiedAdsCommandService( IAggregateStore store, ICurrencyLookup currencyLookup, UploadFile uploader) : base(store) { CreateWhen <V1.Create>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (cmd, id) => ClassifiedAd.Create( ClassifiedAdId.FromGuid(id), UserId.FromGuid(cmd.OwnerId) ) ); UpdateWhen <V1.ChangeTitle>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.SetTitle(ClassifiedAdTitle.FromString(cmd.Title)) ); UpdateWhen <V1.UpdateText>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.UpdateText(ClassifiedAdText.FromString(cmd.Text)) ); UpdateWhen <V1.UpdatePrice>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.UpdatePrice( Price.FromDecimal( cmd.Price, cmd.Currency ?? "EUR", currencyLookup ) ) ); UpdateWhen <V1.RequestToPublish>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.RequestToPublish() ); UpdateWhen <V1.Publish>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.Publish(UserId.FromGuid(cmd.ApprovedBy)) ); UpdateWhen <V1.Delete>( cmd => ClassifiedAdId.FromGuid(cmd.Id), (ad, cmd) => ad.Delete() ); UpdateWhen <V1.UploadImage>( cmd => ClassifiedAdId.FromGuid(cmd.Id), async(ad, cmd) => ad.AddPicture( await uploader(cmd.Image), new PictureSize(2000, 2000) ) ); }
protected Money(Decimal amount, string currencyCode, ICurrencyLookup currencyLookup) { this.CheckRule(new CurrencyShouldBeSpecified(currencyCode)); this.CheckRule(new AmountShouldBePositive(amount)); var currency = currencyLookup.FindCurrency(currencyCode); this.CheckRule(new CurrencySouldBeInUse(currencyCode, currency.InUse)); this.CheckRule(new AmountShouldBeDecimalPlacesLessThanCurrencypublic(amount, currency.DecimalPlaces, currencyCode)); this.Amount = amount; this.Currency = currency; }
public static IMvcCoreBuilder AddAdsModule( this IMvcCoreBuilder builder, string databaseName, ICurrencyLookup currencyLookup, UploadFile uploadFile ) { EventMappings.MapEventTypes(); builder.Services.AddSingleton( c => new ClassifiedAdsCommandService( c.GetAggregateStore(), currencyLookup, uploadFile ) ); builder.Services.AddSingleton( c => { var store = c.GetRavenStore(); store.CheckAndCreateDatabase(databaseName); IAsyncDocumentSession GetSession() => c.GetRavenStore() .OpenAsyncSession(databaseName); return(new SubscriptionManager( c.GetEsConnection(), new RavenDbCheckpointStore( GetSession, SubscriptionName ), SubscriptionName, StreamName.AllStream, new RavenDbProjection <ClassifiedAdDetails>( GetSession, ClassifiedAdDetailsProjection.GetHandler ), new RavenDbProjection <MyClassifiedAds>( GetSession, MyClassifiedAdsProjection.GetHandler ) )); } ); builder.AddApplicationPart(typeof(AdsModule).Assembly); return(builder); }
public ClassifiedAdsCommandService( IAggregateStore store, ICurrencyLookup currencyLookup) : base(store) { CreateWhen <V1.Create>( cmd => new ClassifiedAdId(cmd.Id), (cmd, id) => ClassifiedAd.Create( new ClassifiedAdId(id), new UserId(cmd.OwnerId) ) ); UpdateWhen <V1.ChangeTitle>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.SetTitle(ClassifiedAdTitle.FromString(cmd.Title)) ); UpdateWhen <V1.UpdateText>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.UpdateText(ClassifiedAdText.FromString(cmd.Text)) ); UpdateWhen <V1.UpdatePrice>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.UpdatePrice( Price.FromDecimal(cmd.Price, cmd.Currency ?? "EUR", currencyLookup) ) ); UpdateWhen <V1.RequestToPublish>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.RequestToPublish() ); UpdateWhen <V1.Publish>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.Publish(new UserId(cmd.ApprovedBy)) ); UpdateWhen <V1.Delete>( cmd => new ClassifiedAdId(cmd.Id), (ad, cmd) => ad.Delete() ); }
protected Money(decimal amount, CurrencyCode currencyCode, ICurrencyLookup currencyLookup) { 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 ArgumentOutOfRangeException( nameof(amount), $"Amount in {currencyCode} cannot have more than {currency.DecimalPlaces} decimals"); } Amount = amount; Currency = currency; }
private Money(decimal value, string currencyCode, ICurrencyLookup currencyLookup) { if (string.IsNullOrWhiteSpace(currencyCode)) { throw new ArgumentException($"{ nameof(currencyCode) } is required"); } var currency = currencyLookup.FindCurrency(currencyCode); if (!currency.IsEnabled) { throw new CurrencyException($"{ nameof(currencyCode) } is not enabled"); } if (decimal.Round(value, currency.DecimalDigits) != value) { throw new ArgumentOutOfRangeException($"Amount in { currencyCode } must have { currency.DecimalDigits } as maximum"); } Value = value; Currency = currency; }
public static Money FromDecimal(decimal amount, string currency, ICurrencyLookup currencyLookup) => new Money(amount, currency, currencyLookup);
public static Money FromString(String amount, string currency, ICurrencyLookup currencyLookup) => new Money(decimal.Parse(amount), currency, currencyLookup);
public static Money FromString(string value, string currencyCode, ICurrencyLookup currencyLookup) { var parsed = decimal.Parse(value, CultureInfo.InvariantCulture); return(new Money(parsed, currencyCode, currencyLookup)); }
public static Money FromDecimal(decimal value, string currencyCode, ICurrencyLookup currencyLookup) { return(new Money(value, currencyCode, currencyLookup)); }
public static new Price FromDecimal(decimal amount, string currency, ICurrencyLookup currencyLookup) { return(new Price(amount, currency, currencyLookup)); }
public ClassifiedAdsApplicationService(IEntityStore store, ICurrencyLookup currencyLookup) { _store = store; _currencyLookup = currencyLookup; }
public ClassifiedAdsService(IAggregateStore store, IFailoverPolicyProvider failoverPolicyProvider, ICurrencyLookup currencyLookup) { this.store = store; failoverPolicy = failoverPolicyProvider.CommandRetryPolicy; this.currencyLookup = currencyLookup; }
public static Money FromDecimal(decimal amount, CurrencyCode currencyCode, ICurrencyLookup currencyLookup) => new Money(amount, currencyCode, currencyLookup);
public static new Price FromDecimal(decimal amount, string currencyCode, ICurrencyLookup currencyLookup) => new Price(amount, currencyCode, currencyLookup);
public static Money Zero(string currencyCode, ICurrencyLookup currencyLookup) { return(new Money(decimal.Zero, currencyCode, currencyLookup)); }
public MoneyWrapper(ICurrencyLookup currencyLookup) { this.currencyLookup = currencyLookup; }
public ProductCommandHandler(ICurrencyLookup currencyLookup, IProductRepository repository) { _currencyLookup = currencyLookup; _repository = repository; }