private void DiscarReservation(ReservationDiscarded reservation) { var reservationToRemove = _state.Reservations.SingleOrDefault(x => x.ReservationId == reservation.ReservationId); if (reservationToRemove == null) { return; } _state.Reservations.Remove(reservationToRemove); }
protected override void OnCommand(object message) { switch (message) { case ReserveSeat m: { var reservationCreated = new ReservationCreated(m.CustomerId, m.OrderId, m.EventId, m.ReservationId, m.SceneSeatId); Persist(reservationCreated, @event => { ReserveSeat(@event); SaveSnapshotIfNeeded(); Context.PublishEvent(@event); }); } break; case DiscardSeat m: { var reservationCreated = new ReservationDiscarded(m.OrderId, m.EventId, m.ReservationId); Persist(reservationCreated, @event => { DiscarReservation(@event); SaveSnapshotIfNeeded(); Context.PublishEvent(@event); }); } break; case Terminated m: { } break; default: Unhandled(message); break; } }
private void Handle(ReservationDiscarded @event) { var reservationToRemove = _state.Reservations.Single(x => x.Id == @event.ReservationId); _state.Reservations.Remove(reservationToRemove); }