Ejemplo n.º 1
0
        public ActionResult Create(AppointmentFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Doctors = _unitOfWork.Doctors.GetAvailableDoctors();
                return(View(viewModel));
            }
            var appointment = new AppointmentCreateDto()
            {
                StartDateTime = viewModel.GetStartDateTime(),
                Detail        = viewModel.Detail,
                Status        = false,
                PatientId     = viewModel.Patient,
                DoctorId      = viewModel.Doctor
            };

            var appointmentApi = new AppointmentController(_unitOfWork); // since it is from the same assemnly (need to check the dependency injection)
            var result         = appointmentApi.CreateAppointment(appointment);

            if (result is OkResult)
            {
                return(RedirectToAction("Index", "Appointments"));
            }

            // Should with errors being displayed
            return(View("Index", viewModel));
        }
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     if (isValidData())
     {
         if (txtReason.Text.Length < 10)
         {
             MessageBox.Show("Reason should be longer than 10 characters.");
             return;
         }
         else if (dtpDateTime.Value < DateTime.Now)
         {
             MessageBox.Show("You can not create an appointment for the past!");
             return;
         }
         else
         {
             newAppointment = new Appointment();
             this.PutIncidentData(newAppointment);
             try
             {
                 newAppointment.ApptID = AppointmentController.CreateAppointment(newAppointment);
                 MessageBox.Show("The appointment was successfully created.");
                 this.Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }
        public void CreateAppointmentAction_LoadsCreateAppointmentPage_ReturnsCreateAppointmentView()
        {
            //Arrange
            var controller = new AppointmentController(logger.Object, appointmentRepo.Object, practitionerRepo.Object, patientRepo.Object, userRepo.Object, validator.Object);

            //Act
            var result = controller.CreateAppointment() as ViewResult;

            //Assert
            Assert.AreEqual("CreateAppointment", result.ViewName);
        }
        private void addBtn_Click(object sender, EventArgs e)
        {
            /*var chosenPatient = patientIDCB.SelectedItem;
            *  var chosenStaff = staffIDCB.SelectedItem;
            *  var chosenTime = timeCB.SelectedItem;
            *  var chosenDate = appointmentDatePicker.Value;*/

            if (patientIDCB.SelectedValue == null || staffIDCB.SelectedValue == null || timeCB.SelectedValue == null)
            {
                MessageBox.Show("Error!", "Please Fill all Required Fields",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                var chosenTime = timeCB.SelectedItem.ToString();
                var chosenDate = appointmentDatePicker.Value;
                //string[] GetPatID = patientIDCB.SelectedText.Split(':');
                //int patientID = Int32.Parse(GetPatID[0]);
                var GetPatientID = patientIDCB.GetItemText(patientIDCB.SelectedItem);
                var pID          = GetPatientID.Split(':').First();
                int patientID    = Int32.Parse(pID);
                var GetStaffID   = staffIDCB.GetItemText(staffIDCB.SelectedItem);
                var sID          = GetStaffID.Split(':').First();
                int staffID      = Int32.Parse(sID);
                //      Cut the chosenStaff/chosenPatients strings to only the number before the ':'
                //      Parse those string numbers into integers
                var allAppointments = AppointmentController.CreateAppointment(staffID, patientID, chosenTime, chosenDate.ToString("dd/MM/yyyy"));

                if (allAppointments.Any())
                {
                    appListBox.DataSource = allAppointments;
                    MessageBox.Show("Success!", "Appointment created.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    MessageBox.Show("Error!", "Appoitment couldn't be added.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // Successful might be bool 'true' if the record is saved. Else, we want to send back an error to the view here
                //  if it wasn't written to the Database. Pop up a message box if it works to say 'Added' and one to say 'Not Added'
                //  if it was unsuccessful, and put the error message in the message box.
            }
        }
        private void CreateAppointmentButton_Click(object sender, EventArgs e)
        {
            string      appointmentName        = appointmentNameTextBox.Text;
            string      appointmentDescription = appointmentDescriptionRichTextBox.Text;
            DateTime    appointmentStartDate   = appointmentStartDateDateTimePicker.Value;
            DateTime    appointmentEndDate     = appointmentEndDateDateTimePicker.Value;
            Appointment newappointment         = new Appointment(appointmentName, appointmentDescription, appointmentStartDate, appointmentEndDate);
            bool        couldTheappointmentBeCreated;
            string      feedbackText;

            (couldTheappointmentBeCreated, feedbackText) = AppointmentController.CreateAppointment(newappointment);
            if (couldTheappointmentBeCreated)
            {
                appointmentNameTextBox.Clear();
                appointmentDescriptionRichTextBox.Clear();
                calendar.ShowSelectedDisplay();
            }
            MessageBox.Show(feedbackText);
        }