Ejemplo n.º 1
0
        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));
                        });
                    }
                }
            }
        }