private void AddAppointment_OnClick(object sender, RoutedEventArgs e) { var selectedAppointment = this.AvailableAppointments.SelectedItem as AvailableAppointmentRowDto; var selectedSpecialist = this.Specialists.SelectedIndex; if (selectedSpecialist < 0 || selectedAppointment == null) { return; } var specialist = this._currentSpecialists[selectedSpecialist]; var appointment = new Appointment { Id = Guid.NewGuid(), StartDate = (DateTime)selectedAppointment.StartDate, EndDate = (DateTime)selectedAppointment.EndDate, SpecialistId = specialist.Id }; var appointmentService = new AppointmentsService(); appointmentService.AddNewAppointment(appointment); MessageBox.Show("Dodano nową wizytę"); }