public async Task Handle(PartyShippingAddressChangedEvent message) { if (message.EffectiveDate > DateTime.UtcNow) { await _bus.Defer(message.EffectiveDate - DateTime.UtcNow, message); return; } 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(); } }
/// <summary> /// Apply an event to the current instance /// </summary> /// <param name="evt">The event</param> public void ApplyEvent([AggregateId(nameof(PartyShippingAddressChangedEvent.PartyId))] PartyShippingAddressChangedEvent evt) { var shippingAddress = new PostalAddress(evt.Address, evt.City, evt.Country) { PostalCode = evt.PostalCode, Province = evt.Province }; this.ShippingAddress = shippingAddress; }
/// <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> /// <param name="effectiveDate">The country</param> public void ChangeShippingAddress(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 shipping address to an effective date before the registration date", nameof(effectiveDate)); } var e = new PartyShippingAddressChangedEvent(Id, address, city, postalCode, province, country, effectiveDate); RaiseEvent(e); }
public async Task Handle(PartyShippingAddressChangedEvent message) { using (var context = new RegistryDbContext(Options)) { 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(); } }