public AppointmentInformationForm(Appointment appointment, CalendarForm calendarForm, AppointmentController appointmentController, UserController userController, AppointmentsInDayForm appointmentsInDayForm = null) { InitializeComponent(); if (appointment == null) { throw new ArgumentNullException("appointment"); } this.appointment = appointment; calendar = calendarForm; if (appointmentsInDayForm != null) { appointmentsInDayForm.Close(); } FillFields(); HideOwnerButtonsIfLoggedUserDoesNotOwnTheAppointment(); this.appointmentController = appointmentController; this.userController = userController; }
private void EditAppointmentButton_Click(object sender, EventArgs e) { List <string> appointmentGuests = GetAppointmentGuests(); Appointment editedAppointment = new Appointment(appointmentTitleTextBox.Text, appointmentDescriptionRichTextBox.Text, appointmentStartDateDateTimePicker.Value, appointmentEndDateDateTimePicker.Value, UserController.LoggedUserName, appointmentGuests); bool appointmentHasTitle = !String.IsNullOrWhiteSpace(editedAppointment.Title); bool appointmentHasDescription = !String.IsNullOrWhiteSpace(editedAppointment.Description); bool appointmentEndDateIsLaterThanStartDate = editedAppointment.StartDate < editedAppointment.EndDate; List <string> userNamesThatCannotBeInvitedToAppointment = appointmentController.GetUserNamesThatCannotBeInvitedToAppointment(appointmentGuests, editedAppointment); bool areAllTheGuestsCorrect = userNamesThatCannotBeInvitedToAppointment.Count.Equals(Constants.ZeroItemsInList); bool areTheAppointmentValuesCorrect = appointmentHasTitle && appointmentHasDescription && appointmentEndDateIsLaterThanStartDate; bool couldTheAppointmentBeCreated = areTheAppointmentValuesCorrect && areAllTheGuestsCorrect; if (couldTheAppointmentBeCreated) { appointmentController.DeleteAppointment(appointment); appointmentController.SaveAppointment(editedAppointment); appointmentInformation.UpdateFields(editedAppointment); calendar.ShowSelectedDisplay(); MessageBox.Show("Successfully edited appointment"); if (appointmentsInDay != null) { appointmentsInDay.Close(); } this.Close(); } else { if (!areTheAppointmentValuesCorrect) { string errorFeedbackText = appointmentController.GetErrorFeedbackTextCreatingAppointmentWithWrongValues(appointmentHasTitle, appointmentHasDescription, appointmentEndDateIsLaterThanStartDate); MessageBox.Show(errorFeedbackText, "Error"); } if (!areAllTheGuestsCorrect) { string errorFeedbackText = appointmentController.GetErrorFeedbackTextCreatingAppointmentWithWrongGuests(userNamesThatCannotBeInvitedToAppointment); MessageBox.Show(errorFeedbackText, "Error"); } } }