public ActionResult AssignRoles(int?UserTypeID) { if (UserTypeID.HasValue && UserTypeID.Value > 0) { ViewBag.UserType = new SelectList(dbUser.getUserTypes(), "UserTypeID", "Description", UserTypeID.Value); var reqAccessRoleToUserType = dbUser.getAccessByUserType(UserTypeID.Value).Select(x => x.RoleId).ToList(); var roleLst = dbUser.getRoles().Where(x => !reqAccessRoleToUserType.Contains(x.RoleId)).ToList(); var AssignedroleLst = dbUser.getRoles().Where(x => reqAccessRoleToUserType.Contains(x.RoleId)).ToList(); if (roleLst != null && roleLst.Count > 0) { ViewBag.Roles = new SelectList(roleLst, "RoleId", "RoleName", "Header", roleLst.First()); } else { ViewBag.Roles = new SelectList(new List <SelectListItem>() { new SelectListItem { Value = "0", Text = "All Roles Assinged" } }, "value", "text"); // new SelectList(temp, "RoleId", "RoleName", "Header", temp.First()); } if (AssignedroleLst != null && AssignedroleLst.Count > 0) { ViewBag.AssignedRoles = new SelectList(AssignedroleLst, "RoleId", "RoleName", "Header", AssignedroleLst.First()); } else { ViewBag.AssignedRoles = new SelectList(new List <SelectListItem>() { new SelectListItem { Value = "0", Text = "No Assigned Roles" } }, "value", "text"); // new SelectList(temp, "RoleId", "RoleName", "Header", temp.First()); } } else { ViewBag.UserType = new SelectList(dbUser.getUserTypes(), "UserTypeID", "Description"); var temp = dbUser.getRoles(); ViewBag.Roles = new SelectList(temp, "RoleId", "RoleName", "Header", temp.First()); ViewBag.AssignedRoles = new SelectList(new List <SelectListItem>() { new SelectListItem { Value = "0", Text = "No Assigned Roles" } }, "value", "text"); // new SelectList(temp, "RoleId", "RoleName", "Header", temp.First()); } return(View()); }
public ActionResult RolesIndex() { var reqRoles = dbUser.getRoles(); return(View(reqRoles)); }