예제 #1
0
        public async Task <IActionResult> OnPostAsync(int selectedDoctorId, int[] selectedReasonsIds, DateTime pickedDate)
        {
            if (ModelState.IsValid)
            {
                if (pickedDate < DateTime.UtcNow)
                {
                    ModelState.AddModelError("Date", _cultureLocalizer.Text("Date must be from the future"));
                }
                else
                {
                    Appointment.Doctor = new Doctor()
                    {
                        UserId = selectedDoctorId
                    };
                    if (selectedReasonsIds.Length > 0)
                    {
                        Appointment.AppointmentReasons = new List <Appointment2Reason>();
                        Array.ForEach(selectedReasonsIds, (reasonId) =>
                        {
                            Appointment.AppointmentReasons.Add(new Appointment2Reason()
                            {
                                ReasonId = reasonId
                            });
                        });
                    }
                    var patientId = AuthenticationUtils.GetPatientId(HttpContext);
                    if (patientId.HasValue)
                    {
                        Appointment.Patient = new Patient()
                        {
                            UserId = patientId.Value
                        };
                    }


                    Appointment.AppointmentDate = pickedDate;
                    appointmentsSetResponse     = await _appointmentsService.SetAppointment(Appointment);

                    if (appointmentsSetResponse == AppointmentSetResponse.CORRECT)
                    {
                        HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Appointments/AppointmentMade"));

                        return(null);
                    }
                }
            }


            await OnGetAsync();

            SelectedDoctor = selectedDoctorId;
            SelectedResons = selectedReasonsIds;
            Date           = pickedDate;
            return(Page());
        }