예제 #1
0
        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;
        }
예제 #2
0
 public Price(decimal amount, string currencyCode, ICurrencyLookup currencyLookup) : base(amount, currencyCode, currencyLookup)
 {
     if (amount < 0)
     {
         throw new ArgumentException("Price cannot be negative", nameof(amount));
     }
 }
예제 #3
0
        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;
 }
예제 #7
0
 Price(decimal value, string currencyCode, ICurrencyLookup currencyLookup) : base(value, currencyCode, currencyLookup)
 {
     if (value < 0)
     {
         throw new ArgumentException("Price cannot be negative", nameof(value));
     }
 }
예제 #8
0
        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)
                    )
                );
        }
예제 #9
0
        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;
        }
예제 #10
0
        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()
                );
        }
예제 #12
0
        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;
        }
예제 #13
0
        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;
        }
예제 #14
0
 public static Money FromDecimal(decimal amount, string currency, ICurrencyLookup currencyLookup) =>
 new Money(amount, currency, currencyLookup);
예제 #15
0
 public static Money FromString(String amount, string currency, ICurrencyLookup currencyLookup) =>
 new Money(decimal.Parse(amount), currency, currencyLookup);
예제 #16
0
        public static Money FromString(string value, string currencyCode, ICurrencyLookup currencyLookup)
        {
            var parsed = decimal.Parse(value, CultureInfo.InvariantCulture);

            return(new Money(parsed, currencyCode, currencyLookup));
        }
예제 #17
0
 public static Money FromDecimal(decimal value, string currencyCode, ICurrencyLookup currencyLookup)
 {
     return(new Money(value, currencyCode, currencyLookup));
 }
예제 #18
0
 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;
 }
예제 #21
0
 public static Money FromDecimal(decimal amount, CurrencyCode currencyCode, ICurrencyLookup currencyLookup) =>
 new Money(amount, currencyCode, currencyLookup);
예제 #22
0
 public static new Price FromDecimal(decimal amount, string currencyCode, ICurrencyLookup currencyLookup) =>
 new Price(amount, currencyCode, currencyLookup);
예제 #23
0
 public static Money Zero(string currencyCode, ICurrencyLookup currencyLookup)
 {
     return(new Money(decimal.Zero, currencyCode, currencyLookup));
 }
예제 #24
0
 public MoneyWrapper(ICurrencyLookup currencyLookup)
 {
     this.currencyLookup = currencyLookup;
 }
예제 #25
0
 public ProductCommandHandler(ICurrencyLookup currencyLookup, IProductRepository repository)
 {
     _currencyLookup = currencyLookup;
     _repository     = repository;
 }