示例#1
0
            public async Task Handle(CustomerCreated notification, CancellationToken cancellationToken)
            {
                var @event = await _eventStore.GetEvent(notification.EventId);

                var entity = new Customer
                {
                    Id      = notification.AggregateId,
                    Created = @event.TimeStamp
                };
                var redux = new ReduxStore <Customer>(Customer.Reducer, entity);

                redux.Dispatch(notification.Action);

                await _context.Customers.AddAsync(entity, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);
            }
            public async Task Handle(CustomerUpdated notification, CancellationToken cancellationToken)
            {
                var entity = await _context.Customers.FindAsync(notification.AggregateId);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Customer), notification.AggregateId);
                }

                var redux = new ReduxStore <Customer>(Customer.Reducer, entity);

                foreach (var action in notification.Actions)
                {
                    redux.Dispatch(action);
                }

                await _context.SaveChangesAsync(cancellationToken);
            }