public ActionResult AddCohortUsers(CohortUsers users)
 {
     db.addCohortUsers(users.getIdsToAdd(), users.ProgramCohortID);
     return RedirectToAction("CohortUsers", new { ProgramCohortID = users.ProgramCohortID });
 }
        /////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult Index(string Command, CohortUsers users = null, int ProgramCohortID = 0)
        {
            if (Command == "AddUsers")
                db.addCohortUsers(users.getIdsToAdd(), users.ProgramCohortID);
            else if (Command == "RemoveUsers")
                db.removeCohortUsers(users.getIdsToRemove(), users.ProgramCohortID);

            IEnumerable<ProgramCohort> model = db.getCohorts();
            ViewBag.ProgramCohortID = ProgramCohortID;

            return View(model);
        }
 public ActionResult RemoveCohortUsers(CohortUsers users)
 {
     db.removeCohortUsers(users.getIdsToRemove(), users.ProgramCohortID);
     return RedirectToAction("CohortUsers", new { ProgramCohortID = users.ProgramCohortID });
 }
        public CohortUsers getCohortUsers(int ProgramCohortID)
        {
            CohortUsers users = new CohortUsers();
            users.ProgramCohortID = ProgramCohortID;

            int FacultyRoleID = db.Roles.Single(r => r.Name == "Faculty").Id;
            int CandidateRoleID = db.Roles.Single(r => r.Name == "Candidate").Id;

            foreach (User user in db.Users.Where(u => u.Roles.FirstOrDefault(r => r.RoleId == CandidateRoleID || r.RoleId == FacultyRoleID) != null).
                OrderBy(u=> u.LastName))
            {
                SelectableUser selectableuser = new SelectableUser()
                {
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Id = user.Id,
                    Selected = false,
                    Role = user.Roles.FirstOrDefault(r => r.RoleId == CandidateRoleID) != null ? RoleEnum.Candidate : RoleEnum.Faculty
                };
                if (user.CohortEnrollments.FirstOrDefault(e => e.ProgramCohortID == ProgramCohortID) != null)
                {
                    if (selectableuser.Role == RoleEnum.Candidate)
                        users.EnrolledCandidates.Add(selectableuser);
                    else
                        users.EnrolledFaculty.Add(selectableuser);
                }
                else
                {
                    if (selectableuser.Role == RoleEnum.Candidate)
                        users.NonEnrolledCandidates.Add(selectableuser);
                    else
                        users.NonEnrolledFaculty.Add(selectableuser);
                }
            }
            return users;
        }