public IActionResult Index() { RoleRepo roleRepo = new RoleRepo(_context); // IEnumerable < RoleRepo > = roleRepo.GetAllRoles(); return(View(roleRepo.GetAllRoles())); }
public ActionResult Assign(string userName) { ViewBag.SelectedUser = userName; RoleRepo roleRepo = new RoleRepo(_context); var roles = roleRepo.GetAllRoles().ToList(); var preRoleList = roles.Select(r => new SelectListItem { Value = r.RoleName, Text = r.RoleName }) .ToList(); var roleList = new SelectList(preRoleList, "Value", "Text"); ViewBag.RoleSelectList = roleList; var userList = _context.Users.ToList(); var preUserList = userList.Select(u => new SelectListItem { Value = u.Email, Text = u.Email }).ToList(); SelectList userSelectList = new SelectList(preUserList, "Value", "Text"); ViewBag.UserSelectList = userSelectList; return(View()); }
public ActionResult Create(string userName) { var roles = _roleRepo.GetAllRoles().ToList(); var preRoleList = roles.Select(r => new SelectListItem { Value = r.RoleName, Text = r.RoleName }).ToList(); var roleList = new SelectList(preRoleList, "Value", "Text"); ViewBag.RoleSelectList = roleList; var user = _userRepo.FineOne(userName); return(View(new UserRoleVM { Id = user.ID, Email = user.Email, Role = "" })); }
public ActionResult Remove(string userName, string role) { // Store the email address of the Identity user // which is their user name. ViewBag.SelectedUser = userName; ViewBag.SelectedRole = role; // Build SelectList with role data and store in ViewBag. RoleRepo roleRepo = new RoleRepo(_context); var roles = roleRepo.GetAllRoles().ToList(); // There may be a better way but I have always found using the // .NET dropdown lists to be a challenge. Here is a way to make // it work if you can get the data in the proper format. // 1. Preparation for 'Roles' drop down. // a) Build a list of SelectListItem objects which have 'Value' and // 'Text' properties. var preRoleList = roles.Select(r => new SelectListItem { Value = r.RoleName, Text = r.RoleName }) .ToList(); // b) Store the SelectListItem objects in a SelectList object // with 'Value' and 'Text' properties set specifically. var roleList = new SelectList(preRoleList, "Value", "Text"); // c) Store the SelectList in a ViewBag. ViewBag.RoleSelectList = roleList; // 2. Preparation for 'Users' drop down list. // a) Build a list of SelectListItem objects which have 'Value' and // 'Text' properties. var userList = _context.Users.ToList(); // b) Store the SelectListItem objects in a SelectList object // with 'Value' and 'Text' properties set specifically. var preUserList = userList.Select(u => new SelectListItem { Value = u.Email, Text = u.Email }).ToList(); SelectList userSelectList = new SelectList(preUserList, "Value", "Text"); // c) Store the SelectList in a ViewBag. ViewBag.UserSelectList = userSelectList; return(View()); }
public ActionResult Create(string userName) { ViewBag.SelectedUser = userName; var roles = _roleRepo.GetAllRoles().ToList(); var preRoleList = roles.Select(r => new SelectListItem { Value = r.RoleName, Text = r.RoleName }).ToList(); ViewBag.RoleSelectList = new SelectList(preRoleList, "Value", "Text");; var userList = _userRepo.All(); var preUserList = userList.Select(u => new SelectListItem { Value = u.UserName, Text = u.UserName }).ToList(); ViewBag.UserSelectList = new SelectList(preUserList, "Value", "Text"); return(View()); }
// GET: Role public ActionResult Index() { RoleRepo roleRepo = new RoleRepo(_context); return(View(roleRepo.GetAllRoles())); }
public ActionResult Index() { return(View(_roleRepo.GetAllRoles())); }