private void Save() { try { var appointment = new AppointmentModel { TeacherName = txtTName.Text.Trim(), Reason = txtReason.Text.Trim(), ADate = YearPicker.Value }; ValidationContext context = new ValidationContext(appointment); List <ValidationResult> errorList = new List <ValidationResult>(); var error = string.Empty; if (!Validator.TryValidateObject(appointment, context, errorList, true)) { foreach (ValidationResult result1 in errorList) { error = error + result1.ErrorMessage + "\r\n"; } MessageBox.Show(error); return; } var data = new AppointmentData(); bool result = data.SaveAppointment(appointment); if (result) { MessageBox.Show("Appointment place Sucessfully"); this.Hide(); HomePage3 h3 = new HomePage3(); h3.ShowDialog(); } else { MessageBox.Show("Appointment place unsucessfully"); } } catch (Exception ex) { throw ex; } }
public void RegisterAppointment(AppointmentModels _appointment) { AppointmentData appointmentData = new AppointmentData(); appointmentData.SaveAppointment(_appointment); }