Beispiel #1
0
        public IActionResult Create()
        {
            var logged_usr_id        = signInManager.UserManager.GetUserId(User);
            var logged_user_hospital = userManager.Users
                                       .Where(usr => usr.Id == logged_usr_id)
                                       .FirstOrDefault();

            var all_patients           = context.Patients.Where(pat => pat.Hospital.HospitalId == logged_user_hospital.HospitalId).Count();
            var all_requested_patients = context.RequestPatients.Where(rp => rp.hospitalId == logged_user_hospital.HospitalId).Count();

            if ((all_patients + all_requested_patients) >= logged_user_hospital.MaxBeds)
            {
                //add error
                TempData["ErrorMessage"] = "Sorry !! All Beds are full in the Hospital!";
                return(RedirectToAction("Index", "Patient"));
            }

            var citizen_hospital_usr = context.CitizenHospitals.Where(ch => ch.Hospital.HospitalId == logged_user_hospital.HospitalId).ToList();
            List <ApplicationUser> citizen_user_list = new List <ApplicationUser>();
            var citizens = citizenRepository.GetAllCitizens();


            List <SelectListItem> selectListItems = new List <SelectListItem>();

            foreach (var ch in citizen_hospital_usr)
            {
                citizen_user_list.Add(citizens.Where(usr => usr.CitizenId == ch.CitizenId).FirstOrDefault());
            }

            foreach (var item in citizen_user_list)
            {
                selectListItems.Add(new SelectListItem {
                    Text = item.Name + " " + item.Email, Value = item.CitizenId.ToString()
                });
            }

            ViewBag.citizen_list = selectListItems;
            return(View());
        }