public async Task Initialize(InitializeBookStoreCommand cmd) { var @event = new BookStoreInitializedEvent( cmd.Id, cmd.Name, new AddressEventData(cmd.Address.Country, cmd.Address.City, cmd.Address.Street, cmd.Address.Building)); RaiseEvent(@event); await ConfirmEvents(); }
private async Task Apply(BookStoreInitializedEvent @event, long version) { using (var db = new ApplicationDbContext(Configuration.ConnectionString)) { await UpdateStreamVersion(db, version); CreateBookStore(db, @event); await db.SaveChangesAsync(); } }
public void Apply(BookStoreInitializedEvent @event) { Id = @event.Id; Name = @event.Name; Address = new AddressData { Country = @event.Address.Country, City = @event.Address.City, Street = @event.Address.Street, Building = @event.Address.Building }; }
private void CreateBookStore(ApplicationDbContext db, BookStoreInitializedEvent @event) { _log.Debug($"Creating book store entity {@event.Id}"); var bookStore = new Database.Entities.BookStore { Id = @event.Id, Name = @event.Name, Address = JsonConvert.SerializeObject(@event.Address) }; db.BookStores.Add(bookStore); }