public IActionResult AddAppointment(AddAppointmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var succeeded = _patientService.UpdateBackground(model.PatientId, model.PatientBackground);

                if (!succeeded)
                {
                    return(this.InternalServerError());
                }

                Debug.Assert(model.Date != null, "model.Date != null");
                Debug.Assert(model.Time != null, "model.Time != null");
                var appointmentDateTime = model.Date.Value.Date + model.Time.Value.TimeOfDay;

                var error = _appointmentsService.AddAppointment(new AddAppointmentRequest
                {
                    CreatedAt       = DateTime.Now,
                    Date            = appointmentDateTime,
                    Description     = model.Description,
                    PatientId       = model.PatientId,
                    StaffId         = model.DoctorId,
                    CreatorUserType = UserTypeEnum.STAFF
                });

                switch (error)
                {
                case null:
                    return(RedirectToAction("Index"));

                case ResponseErrorEnum.StaffAlreadyHasAppointmentOnDateTime:
                    ModelState.AddModelError(nameof(model.Time), "The doctor already has an appointment at this time.");
                    break;

                default:
                    return(this.InternalServerError());
                }
            }

            var indexModel = new AppointmentsViewModel();

            FillAppointmentViewModel(indexModel);
            indexModel.AddAppointmentViewModel = model;
            FillAddAppointmentViewModel(model);
            indexModel.OpenAddAppointmentModal = true;
            return(View("Index", indexModel));
        }
        public IActionResult AddRequest(AddRequestViewModel model)
        {
            if (ModelState.IsValid)
            {
                Debug.Assert(model.Date != null, "model.Date != null");
                Debug.Assert(model.Time != null, "model.Time != null");
                var appointmentDateTime = model.Date.Value.Date + model.Time.Value.TimeOfDay;

                var error = _appointmentsService.AddAppointment(new AddAppointmentRequest
                {
                    StaffId         = model.DoctorId,
                    CreatorUserType = UserTypeEnum.PATIENT,
                    PatientId       = CurrentUserId,
                    Description     = model.Description,
                    Date            = appointmentDateTime,
                    CreatedAt       = DateTime.Now
                });

                switch (error)
                {
                case null:
                    return(RedirectToAction("Index"));

                case ResponseErrorEnum.StaffAlreadyHasAppointmentOnDateTime:
                    ModelState.AddModelError(nameof(model.DoctorId), "The doctor already has an appointment at this time.");
                    break;

                case ResponseErrorEnum.RepositoryError:
                    return(this.InternalServerError());
                }
            }

            var indexModel = CreateRequestsViewModel(model);

            return(View("Index", indexModel));
        }