private void ApplyButton_Click(object sender, RoutedEventArgs e) { DateTime?fromDate = FromDatePicker.SelectedDate; if (fromDate == null) { WindowManager.ShowPopupMessage("Please select From date."); return; } _reservation.From = fromDate; DateTime?toDate = ToDatePicker.SelectedDate; if (toDate == null) { WindowManager.ShowPopupMessage("Please select To date."); return; } _reservation.To = toDate; RoomViewObject roomViewObject = (RoomViewObject)RoomsDataGrid.SelectedItem; if (roomViewObject == null) { WindowManager.ShowPopupMessage("Please select room."); return; } _reservation.setRoom(roomViewObject.RoomNumber); GuestViewObject guestViewObject = (GuestViewObject)GuestsDataGrid.SelectedItem; if (guestViewObject == null) { WindowManager.ShowPopupMessage("Please select guest."); return; } _reservation.setGuest(guestViewObject.Id); if (!_dataManager.ReservationValidator.ValidateReservation(_reservation, true)) { return; } if (_isReservationNew) { _reservation.AddToDatabase(_dataManager.Context); WindowManager.ShowPopupMessage($"Created reservation no. {_reservation.Id} on {_reservation.GuestName} {_reservation.GuestSurname}."); } else { _reservation.SaveChangesToDatabase(_dataManager.Context); WindowManager.ShowPopupMessage($"Updated reservation no. {_reservation.Id} on {_reservation.GuestName} {_reservation.GuestSurname}."); } _dataManager.Update(); this.Close(); }
private void FillForm() { if (_reservation == null) { return; } FromDatePicker.SelectedDate = _reservation.From; ToDatePicker.SelectedDate = _reservation.To; int roomNumber = (int)_reservation.RoomNumber; if (roomNumber > 0) { RoomViewObject room = _dataManager.GetRoom(roomNumber); foreach (var obj in RoomsDataGrid.Items) { if (((RoomViewObject)obj).RoomNumber == room.RoomNumber) { RoomsDataGrid.SelectedItem = obj; break; } } } int guestId = (int)_reservation.getGuestId(); if (guestId > 0) { GuestViewObject guest = _dataManager.GetGuest(guestId); foreach (var obj in GuestsDataGrid.Items) { if (((GuestViewObject)obj).Id == guest.Id) { GuestsDataGrid.SelectedItem = obj; break; } } } }