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)); }); } } } }
protected void LoadFile() { if (File.Exists($@"{Environment.CurrentDirectory}\{fileName}")) { XmlSerializer serializer = null; TextReader reader = null; try { serializer = new XmlSerializer(this.GetType()); reader = new StreamReader(fileName); DBDataContext db = (DBDataContext)serializer.Deserialize(reader); this.Species = db.Species; this.Addresses = db.Addresses; this.UserTypes = db.UserTypes; this.Users = db.Users; this.Pets = db.Pets; this.Clients = db.Clients; this.Appointments = db.Appointments; this.Doctors = db.Doctors; this.AppointmentTypes = db.AppointmentTypes; Addresses.ForEach(item => item.Client = Clients.FirstOrDefault(r => r.Id == item.IdClient)); Users.ForEach(item => item.UserType = UserTypes.FirstOrDefault(r => r.Id == item.IdUserType)); Pets.ForEach(item => { item.Specie = Species.FirstOrDefault(r => r.Id == item.IdSpecie); item.Owner = Clients.FirstOrDefault(r => r.Id == item.IdOwner); }); Clients.ForEach(item => { item.Pets = Pets.Where(r => r.IdOwner == item.Id).ToList(); item.Addresses = Addresses.Where(r => r.IdClient == item.Id).ToList(); }); Appointments.ForEach(item => { item.Pet = Pets.FirstOrDefault(r => r.Id == item.IdPet); item.Address = Addresses.FirstOrDefault(r => r.Id == item.IdAddress); item.Doctor = Doctors.FirstOrDefault(r => r.Id == item.IdDoctor); item.Client = Clients.FirstOrDefault(r => r.Id == item.Pet.IdOwner); item.AppointmentType = AppointmentTypes.FirstOrDefault(r => r.Id == item.IdAppointmentType); }); } catch (Exception ex) { throw ex; } finally { if (reader != null) { reader.Close(); } if (serializer != null) { GC.SuppressFinalize(serializer); } } } }