public ActionResult AdminRole() { List <RolesViewModels> list = new List <RolesViewModels>(); ApplicationDbContext dbContext = new ApplicationDbContext(); foreach (var i in dbContext.Users.ToList()) { List <string> roleName = new List <string>(); foreach (var j in i.Roles.ToList()) { if (i.Roles.Count != 0) { roleName.Add(ApplicationRoleManager.GetRoleNameById(j.RoleId)); } } if (i.UserName != "admin") { list.Add(new RolesViewModels() { userId = i.Id, Username = i.UserName, roleName = roleName }); } } return(View(list)); }
public ActionResult EditRole(string id) { ApplicationUser user = UserManager.FindById(id); ViewBag.Description = user.Name + " " + user.LastName; var roleUser = user.Roles; if (roleUser.Count != 0) { ViewBag.Name = ApplicationRoleManager.GetRoleNameById(roleUser.FirstOrDefault().RoleId); } else { ViewBag.Name = null; } return(View()); }