Esempio n. 1
0
        /// <summary>
        /// Apply an event to the current instance
        /// </summary>
        /// <param name="evt">The event</param>
        public void ApplyEvent([AggregateId(nameof(ShippingAddressSetForPartyEvent.PartyId))] ShippingAddressSetForPartyEvent evt)
        {
            var shippingAddress = new PostalAddress(evt.Address, evt.City, evt.Country)
            {
                PostalCode = evt.PostalCode,
                Province   = evt.Province
            };

            this.ShippingAddress = shippingAddress;
        }
Esempio n. 2
0
        /// <summary>
        /// Sets shipping 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>
        public void SetShippingAddress(string address, string city, string postalCode, string province, string country)
        {
            if (string.IsNullOrEmpty(address) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(country))
            {
                throw new InvalidOperationException("A valid address, city and country must be provided");
            }

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

            RaiseEvent(e);
        }
Esempio n. 3
0
        public async Task Handle(ShippingAddressSetForPartyEvent message)
        {
            using (var context = new RegistryDbContext())
            {
                var shippingAddress = 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.ShippingAddress = shippingAddress;

                await context.SaveChangesAsync();
            }
        }