public static OwnershipChanged Create(Identifier id, VehicleOwner owner) { return(new OwnershipChanged { EntityId = id, Owner = owner.OwnerId, Managers = new List <string> { owner.OwnerId }, ModifiedUtc = DateTime.UtcNow }); }
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()}"); } }
public void SetOwnership(VehicleOwner owner) { RaiseChangeEvent(CarsDomain.Events.Car.OwnershipChanged.Create(Id, owner)); }