public void PlaceReservation(int floorIndex, ElevatorDirection direction) { bool reservationExists = _reservations.Exists(r => r.Direction == direction && r.FloorIndex == floorIndex); if (!reservationExists) { var newReservation = new Reservation { Direction = direction, FloorIndex = floorIndex }; _reservations.Add(newReservation); OnReservationPlaced(new ItemEventArgs<IReservation>(newReservation)); } }
public void SetButtonEvents(IReservationSystem reservations, IElevatorController elevatorController) { for (int i = 0; i < _buttonList.Count; i++) { int closedI = i; Button b = _buttonList[i]; b.Click += (sender, args) => reservations.PlaceReservation(closedI, Direction); IReservation reservation = new Reservation { Direction = Direction, FloorIndex = closedI }; b.Click += (sender, args) => elevatorController.HandleButtonPressed(this, new ItemEventArgs<IReservation>(reservation)); } reservations.ReservationPlaced += HandleReservationPlaced; reservations.ReservationRemoved += HandleReservationRemoved; }
public bool Equals(Reservation obj) { if (obj == null) return false; return FloorIndex == obj.FloorIndex && Direction == obj.Direction; }