Ejemplo n.º 1
0
        public async Task Handle(PartyBillingAddressChangedEvent message)
        {
            if (message.EffectiveDate > DateTime.UtcNow)
            {
                await _bus.Defer(message.EffectiveDate - DateTime.UtcNow, message);

                return;
            }
            using (var context = new RegistryDbContext())
            {
                var billingAddress = new PostalAddress()
                {
                    Address    = message.Address,
                    City       = message.City,
                    Country    = message.Country,
                    PostalCode = message.PostalCode,
                    Province   = message.Province
                };
                var party = (from c in context.Parties
                             where c.OriginalId == message.PartyId
                             select c).Single();
                party.BillingAddress = billingAddress;

                await context.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Apply an event to the current instance
        /// </summary>
        /// <param name="evt">The event</param>
        public void ApplyEvent([AggregateId(nameof(PartyBillingAddressChangedEvent.PartyId))] PartyBillingAddressChangedEvent evt)
        {
            var billingAddress = new PostalAddress(evt.Address, evt.City, evt.Country)
            {
                PostalCode = evt.PostalCode,
                Province   = evt.Province
            };

            this.BillingAddress = billingAddress;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets billing address for the party
        /// </summary>
        /// <param name="address">The address</param>
        /// <param name="city">The city</param>
        /// <param name="postalCode">The postal code</param>
        /// <param name="province">The province</param>
        /// <param name="country">The country</param>
        /// <param name="effectiveDate">The country</param>
        public void ChangeBillingAddress(string address, string city, string postalCode, string province, string country, DateTime effectiveDate)
        {
            if (string.IsNullOrEmpty(address) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(country))
            {
                throw new InvalidOperationException("A valid address, city and country must be provided");
            }
            if (effectiveDate < RegistrationDate.ToLocalTime())
            {
                throw new ArgumentException("Cannot change the billing address to an effective date before the registration date", nameof(effectiveDate));
            }

            var e = new PartyBillingAddressChangedEvent(Id, address, city, postalCode, province, country, effectiveDate);

            RaiseEvent(e);
        }