public ActionResult Index(DoctorsPageViewModel model) { ViewBag.Day = DateTime.Now.Date; var userName = User.Identity.Name; Person user = ent.Person.First(u => u.username == userName); DoctorsPageViewModel viewModel = new DoctorsPageViewModel(); viewModel = getUserDoctors(user, viewModel); for (int i = 0; i < model.UsersDoctors.Count; i++) { if (model.UsersDoctors[i].idDoctorChecked) { viewModel.UsersDoctors[i].idDoctorChecked = true; } } for (int i = 0; i < model.DoctorSpecializationDropDown.Count; i++) { if (model.DoctorSpecializationDropDown[i].Selected) { viewModel.DoctorSpecializationDropDown[i].Selected = true; } } //get data int count = 0; foreach (var doctor in model.UsersDoctors) { if (doctor.idDoctorChecked) { count++; List <MedicalRecord> medRec = ent.MedicalRecord.Where(a => (a.doctorId == doctor.personId && a.personId == user.personId)).ToList(); foreach (var mr in medRec) { List <DoctorsAppointment> docApp = ent.DoctorsAppointment.Where(a => a.MedicalRecord.medicalRecordId == mr.medicalRecordId).ToList(); foreach (var app in docApp) { AppointmentViewModel appViewModel = new AppointmentViewModel(); appViewModel.MedicalRecord = mr; appViewModel.Appointment = app; viewModel.Appointments.Add(appViewModel); } } } appointmentList = viewModel.Appointments; } if (count == 0) { appointmentList = new List <AppointmentViewModel>(); } else { viewModel.Appointments = appointmentList.Where(a => a.Appointment.appointmentDate.Month == ViewBag.Day.Month && a.Appointment.appointmentDate.Year == ViewBag.Day.Year).OrderByDescending(a => a.Appointment.appointmentDate).ToList(); } return(View("~/Views/Doctors/Index.cshtml", viewModel)); //return Redirect(Url.RouteUrl(new { controller = "Doctors", action = "Index", viewModel = viewModel }) + "#show-appointments"); }
//static List<AppointmentViewModel> appointmentList = new List<AppointmentViewModel>(); public ActionResult Index() { appointmentList = new List <AppointmentViewModel>(); ViewBag.Day = DateTime.Now.Date; DoctorsPageViewModel viewModel = new DoctorsPageViewModel(); var userName = User.Identity.Name; Person user = ent.Person.First(u => u.username == userName); // all doctors for current user getUserDoctors(user, viewModel); // list of appointments for primary doctor return(View(viewModel)); }
private void Page_Loaded(object sender, RoutedEventArgs e) { ViewModel = new DoctorsPageViewModel(); DataContext = ViewModel; }
private DoctorsPageViewModel getUserDoctors(Person user, DoctorsPageViewModel viewModel) { List <int> userDoctorsIds = new List <int>(); HashSet <DoctorSpecialisation> doctorSpecialisations = new HashSet <DoctorSpecialisation>(); foreach (var mr in ent.MedicalRecord.Where(m => m.personId == user.personId)) { userDoctorsIds.Add(mr.doctorId); } foreach (var drId in userDoctorsIds) { Person doctor = ent.Person.First(u => u.personId == drId); DoctorViewModel doctorViewModel = new DoctorViewModel(); doctorViewModel.personId = doctor.personId; doctorViewModel.firstName = doctor.firstName; doctorViewModel.lastName = doctor.lastName; //Competence foreach (var comp in ent.MedicalRecord.Where(m => m.doctorId == drId)) { if (comp != null) { doctorViewModel.DoctorsSpecialisation.Add(comp.DoctorSpecialisation); } } //Email foreach (var email in ent.Email.Where(m => m.personId == doctor.personId)) { if (email != null) { doctorViewModel.Email.Add(email); } } //PhoneNumber foreach (var num in ent.PhoneNumber.Where(m => m.personId == doctor.personId)) { if (num != null) { doctorViewModel.PhoneNumber.Add(num); } } viewModel.UsersDoctors.Add(doctorViewModel); } viewModel.UsersDoctors.OrderBy(d => d.lastName).ThenBy(d => d.firstName).ToList(); foreach (var mr in ent.MedicalRecord.Where(m => m.personId == user.personId)) { doctorSpecialisations.Add(ent.DoctorSpecialisation.First(d => d.doctorSpecialisationId == mr.doctorSpecialisationId)); } foreach (var s in doctorSpecialisations) { viewModel.DoctorSpecializationDropDown.Add(new SelectListItem() { Text = s.doctorSpecialisation1, Value = s.doctorSpecialisationId.ToString() }); } return(viewModel); }