Ejemplo n.º 1
0
        protected override void OnStateChanged(IChangeEvent @event)
        {
            switch (@event)
            {
            case Events.Car.Created _:
                break;

            case Events.Car.ManufacturerChanged changed:
                Manufacturer = new Manufacturer(changed.Year, changed.Make, changed.Model);
                Recorder.TraceDebug("Car {Id} changed manufacturer to {Year}, {Make}, {Model}", Id, changed.Year,
                                    changed.Make, changed.Model);
                break;

            case Events.Car.OwnershipChanged changed:
                Owner    = new VehicleOwner(changed.Owner);
                Managers = new VehicleManagers();
                Managers.Add(changed.Owner.ToIdentifier());

                Recorder.TraceDebug("Car {Id} changed ownership to {Owner}", Id, Owner);
                break;

            case Events.Car.RegistrationChanged changed:
                Plate = new LicensePlate(changed.Jurisdiction, changed.Number);

                Recorder.TraceDebug("Car {Id} registration changed to {Jurisdiction}, {Number}", Id,
                                    changed.Jurisdiction, changed.Number);
                break;

            case Events.Car.UnavailabilitySlotAdded added:
                var unavailability = new UnavailabilityEntity(Recorder, IdFactory);
                added.EntityId = unavailability.Id;
                unavailability.SetAggregateEventHandler(RaiseChangeEvent);
                RaiseToEntity(unavailability, @event);
                Unavailabilities.Add(unavailability);
                Recorder.TraceDebug("Car {Id} had been made unavailable from {From} until {To}", Id, added.From,
                                    added.To);
                break;

            default:
                throw new InvalidOperationException($"Unknown event {@event.GetType()}");
            }
        }
Ejemplo n.º 2
0
 public void Register(LicensePlate plate)
 {
     RaiseChangeEvent(CarsDomain.Events.Car.RegistrationChanged.Create(Id, plate));
 }