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()); }
public async Task OnGetAsync() { if (Doctor == null) { var doctorId = AuthenticationUtils.GetPatientId(HttpContext); if (doctorId.HasValue) { Doctor = await patientsProfileService.GetDoctor(doctorId.Value); } } }
public async Task OnGetAsync() { if (Patient == null) { var patientId = AuthenticationUtils.GetPatientId(HttpContext); if (patientId.HasValue) { Patient = await patientsProfileService.GetPatient(patientId.Value); } } }
private async Task GetAppointments() { if (Appointments == null) { var patientId = AuthenticationUtils.GetPatientId(HttpContext); if (patientId.HasValue) { if (AuthenticationUtils.IsUserInRole(HttpContext, Role.Doctor)) { IsShownForDoctor = true; Appointments = await appointmentsService.GetAllAppointmentsForDoctor(patientId.Value); } else { IsShownForDoctor = false; Appointments = await appointmentsService.GetAllAppointmentsForUser(patientId.Value); } if (Appointments != null) { var futureAppointments = Appointments.Where(apt => apt.AppointmentDate >= DateTime.UtcNow).ToList(); var pastAppointments = Appointments.Where(apt => apt.AppointmentDate < DateTime.UtcNow).ToList(); futureAppointments = futureAppointments.OrderBy(apt => apt.AppointmentDate).ToList(); pastAppointments = pastAppointments.OrderByDescending(apt => apt.AppointmentDate).ToList(); Appointments = futureAppointments.Concat(pastAppointments).ToList(); LocalizedReasons = new Dictionary <int, string>(); Appointments.ForEach(appointment => { LocalizedReasons.Add(appointment.AppointmentId, GetLozalizedReasons(appointment)); }); } } } }