Example #1
0
 /// <summary>
 /// The event handler method for AppointmentDatatGrid CellContentClick
 /// </summary>
 private void AppointmentDatatGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     appointmentDTO = (AppointmentDTO)appointmentsDataGridView.Rows[e.RowIndex].DataBoundItem;
     if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "ViewVisit")
     {
         Form         appointmmentVisitFormDialog = new AppointmentVisitDialog(appointmentDTO);
         DialogResult result = appointmmentVisitFormDialog.ShowDialog();
     }
     else if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "EditAppointment")
     {
         var _datediff = appointmentDTO.AppointmentDateTime - DateTime.Now;
         if (_datediff.Days >= 1)
         {
             using (Form editAppointmentDialog = new AppointmentInformationDialog(appointmentDTO, patient))
             {
                 DialogResult result = editAppointmentDialog.ShowDialog();
                 if (result == DialogResult.OK || result == DialogResult.Cancel)
                 {
                     this.RefreshDataGrid();
                 }
             }
         }
         else
         {
             MessageBox.Show("Appointments less than 24 hours cannot be edited.", "Unauthorized", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
     else if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "DeleteAppointment")
     {
         var currentAppointment = new Appointment(appointmentDTO.AppointmentID,
                                                  appointmentDTO.PatientID,
                                                  appointmentDTO.DoctorID,
                                                  appointmentDTO.AppointmentDateTime,
                                                  appointmentDTO.ReasonForVisit);
         var visits = this.visitController.GetVisitByAppointment(currentAppointment).Count;
         if (visits < 1)
         {
             string message = "Are you sure you want to delete this appointment?"
                              + Environment.NewLine + $"Doctor: {appointmentDTO.DoctorName}"
                              + Environment.NewLine + $"Appointement Time: {appointmentDTO.AppointmentDateTime.ToLongTimeString()}";
             string caption = $"Delete appointment {appointmentDTO.AppointmentID}";
             var    result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 if (appointmentController.DeleteAppointment(currentAppointment))
                 {
                     MessageBox.Show("Appointment deleted successfully");
                     RefreshDataGrid();
                 }
             }
         }
         else
         {
             MessageBox.Show("Appointment has a visit information and can't be deleted.");
         }
     }
 }
        public void DeleteAppointmentAction_ValidDelete_RedirectsToViewAppointments()
        {
            //Arrange
            var controller = new AppointmentController(logger.Object, appointmentRepo.Object, practitionerRepo.Object, patientRepo.Object, userRepo.Object, validator.Object);

            //Act
            var result = controller.DeleteAppointment(It.IsAny <int>()) as RedirectToActionResult;

            // Assert
            Assert.That(result.ActionName, Is.EqualTo("ViewAppointments"));
        }
        private void DeleteAppointmentButton_Click(object sender, System.EventArgs e)
        {
            string            warningMessage    = "Delete appointment";
            string            warningTitle      = "Are you sure that you want to delete this appointment?";
            MessageBoxButtons messageBoxButtons = MessageBoxButtons.YesNo;
            DialogResult      answer            = MessageBox.Show(warningTitle, warningMessage, messageBoxButtons);

            if (answer == DialogResult.Yes)
            {
                appointmentController.DeleteAppointment(appointment);
                calendar.ShowSelectedDisplay();
                this.Close();
            }
        }
        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");
                }
            }
        }