/// <summary> /// Get all of the pending user accounts and send the user objects to the view. /// </summary> /// <returns></returns> public ActionResult AccountRequests() { ApplicationUserManager manager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); //Get pending users in the system. List<ApplicationUser> pendingUsers = new ApplicationUserService().GetPendingUsers(manager); List<UserInfoModel> userModels = new List<UserInfoModel>(); foreach (ApplicationUser user in pendingUsers) { string fullName = string.Empty; string role = string.Empty; //Check if user is a physician if (user.PhysicianId > 0) { Physician physician = _physicianService.GetPhysician(user.PhysicianId); fullName = physician.FirstName + " " + physician.LastName; role = "Physician"; } //Check if user is an experiment administrator else if (user.ExperimentAdministratorId > 0) { ExperimentAdministrator expAdmin = _experimentAdminService.GetExperimentAdministrator(user.ExperimentAdministratorId); fullName = expAdmin.FirstName + " " + expAdmin.LastName; role = "Experiment Administrator"; } //Get the account request information provided by the user during account request. string accountRequest = accountRequest = _accountRequestService.GetAccountRequest(user.AccountRequestId).ReasonForAccount; UserInfoModel model = new UserInfoModel() { UserId = user.Id, FullName = fullName, Role = role, Status = (Account_Status)user.Status, ReasonForRequest = accountRequest }; userModels.Add(model); } return View(userModels); }
/// <summary> /// Function used to setup and load the initial view for system administrators. /// </summary> /// <returns></returns> public ActionResult ManageUsers() { ApplicationUserManager manager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); //Get all users in the system. List<ApplicationUser> allusers = new ApplicationUserService().GetUserAccounts(manager); List<UserInfoModel> userModels = new List<UserInfoModel>(); //Create a dictionary connecting the user object to the corresponding object that is the correct user type. foreach (ApplicationUser user in allusers) { string fullName = string.Empty; string role = string.Empty; //Check if user is a physician if (user.PhysicianId > 0) { Physician physician = _physicianService.GetPhysician(user.PhysicianId); fullName = physician.FirstName + " " + physician.LastName; role = "Physician"; } //Check if user is an experiment administrator else if (user.ExperimentAdministratorId > 0) { ExperimentAdministrator expAdmin = _experimentAdminService.GetExperimentAdministrator(user.ExperimentAdministratorId); fullName = expAdmin.FirstName + " " + expAdmin.LastName; role = "Experiment Administrator"; } //Check if user is a patient else if (user.PatientId > 0) { //System administrators can't manage patients per requirement 3.1.1.1.4.2 continue; } else { fullName = user.UserName; //Determine if the user is a system admin or has no role. if (user.Roles.Select(r => r.RoleId).Contains(Roles.ADMIN_ROLE_DB_TABLE_ID)) { //If the system admin is the currently logged in system admin do not include them //in the list of users to be managed. if(user.Id == User.Identity.GetUserId()) { continue; } role = "System Administrator"; } else { role = "None"; } } UserInfoModel model = new UserInfoModel() { UserId = user.Id, FullName = fullName, Role = role, Status = (Account_Status)user.Status }; userModels.Add(model); } //Create view model AdminViewModel viewModel = new AdminViewModel(); if (userModels.Count > 0) { viewModel.Users = userModels; } viewModel.SelectedRole = "All Roles"; //Get the list of roles from the database. using (ApplicationDbContext context = new ApplicationDbContext()) { List<string> roles = context.Roles.Select(r => r.Name).ToList(); roles.Sort(); roles.Insert(0, "All Roles"); viewModel.RoleList = new SelectList(roles, viewModel.SelectedRole); } return View(viewModel); }