private void RenovateRoom(object sender, RoutedEventArgs e)
 {
     setDates();
     if (setDestinationRoomId())
     {
         DestinationRoomComboBox.SelectedIndex = 0;
         try
         {
             RenovationDto renovationDto    = CreateRenovationDto(timeInterval);
             SchedulingDto schDto           = renovationDto.toSchedulingDto();
             List <int>    unavailableRooms = roomServerController.GetUnavailableRooms(schDto).ToList();
             if (unavailableRooms.Count > 0)
             {
                 ShowAlternativeRenovationAppointments(unavailableRooms, renovationDto);
             }
             else
             {
                 ScheduleRenovation(schDto);
             }
         }
         catch
         {
             MessageBox.Show("End time must be after start time!", "");
         }
     }
 }
        private void ShowAlternativeRenovationAppointments(List <int> unavailableRooms, RenovationDto renovationDto)
        {
            SchedulingDto dto = renovationDto.toSchedulingDto();
            AlternativeRenovationAppointments newWindow =
                new AlternativeRenovationAppointments(unavailableRooms[0], this, dto);

            newWindow.Show();
        }
        private void AddScheduleRenovationButton(int row, RenovationDto renovation)
        {
            Button scheduleBtn = CreateScheduleButton();

            Grid.SetRow(scheduleBtn, row);
            Grid.SetColumn(scheduleBtn, DynamicGrid.ColumnDefinitions.Count - 2);
            DynamicGrid.Children.Add(scheduleBtn);

            SchedulingDto schDto = renovation.toSchedulingDto();

            timeInterval = new TimeInterval(schDto.TimeInterval.Start, schDto.TimeInterval.End);

            scheduleBtn.Click += (s, e) =>
            {
                List <int> doctors = doctorServerController.GetDoctorsByRoomsAndShifts(schDto).ToList();
                foreach (int doctorId in doctors)
                {
                    renovationServerController.ScheduleRenovation(renovation.TimeInterval, doctorId, AllConstants.PatientIdForRenovation);
                }
                MessageBox.Show("Renovation is successfully scheduled!");
                foreach (Window window in Application.Current.Windows)
                {
                    if (window.GetType() == typeof(RoomRenovation))
                    {
                        if ((window as RoomRenovation).RenovationTypeComboBox.Text.Equals("Complex"))
                        {
                            RoomInformation roomInformation = new RoomInformation(schDto);

                            if ((window as RoomRenovation).ComplexRenovationTypeComboBox.Text.Equals("Separate room"))
                            {
                                roomInformation.MergingStackPanel.Visibility  = Visibility.Hidden;
                                roomInformation.DividingStackPanel.Visibility = Visibility.Visible;
                                roomInformation.Room1Name.Text = mapObjectController.GetMapObjectById(renovation.SourceRoomId).Name;
                                int workTime = mapObjectController.GetMapObjectById(renovation.SourceRoomId).MapObjectDescription.Information.Split("=")[1].Length;
                                roomInformation.WorkTime1.Text = mapObjectController.GetMapObjectById(renovation.SourceRoomId).MapObjectDescription.Information.Split("=")[1].Substring(0, workTime - 1);
                            }
                            else if ((window as RoomRenovation).ComplexRenovationTypeComboBox.Text.Equals("Join rooms"))
                            {
                                roomInformation.DividingStackPanel.Visibility = Visibility.Hidden;
                                roomInformation.MergingStackPanel.Visibility  = Visibility.Visible;
                                roomInformation.RoomName.Text = mapObjectController.GetMapObjectById(renovation.SourceRoomId).Name;
                                int workTime = mapObjectController.GetMapObjectById(renovation.SourceRoomId).MapObjectDescription.Information.Split("=")[1].Length;
                                roomInformation.WorkTime.Text = mapObjectController.GetMapObjectById(renovation.SourceRoomId).MapObjectDescription.Information.Split("=")[1].Substring(0, workTime - 1);
                                List <int> doctors1 = doctorServerController.GetDoctorsByRoomsAndShifts(schDto).ToList();
                                foreach (int doctorId in doctors1)
                                {
                                    startDate = schDto.TimeInterval.Start.AddDays(1);
                                    examinationServerController.ScheduleExamination(startDate, doctorId, AllConstants.PatientIdForRelocation);
                                }
                            }
                            roomInformation.ShowDialog();
                        }
                    }
                }
                this.Close();
            };
        }