private void OnAddReservationCommand() { ReservationWindow window = new ReservationWindow(); bool?result = window.ShowDialog(); if (result == true) { Reservation reservation = (window.DataContext as ReservationWindowViewModel).Reservation; if (reservation != null) { int maxId = 0; if (ReservationData.Count != 0) { maxId = ReservationData.Select(x => x.Id).Max(); } reservation.Id = maxId + 1; ReservationData.Add(reservation); } } }