Beispiel #1
0
 public ActionResult Index(VmUsersList model)
 {
     if (ModelState.IsValid)
     {
         var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
         if (model.button == "Add role")
         {
             UserManager.AddToRole(model.userId, model.RoleName);
         }
         else if (model.button == "Delete role")
         {
             UserManager.RemoveFromRole(model.userId, model.RoleName);
         }
     }
     return(RedirectToAction("Index", "Home"));
 }
Beispiel #2
0
        public ActionResult Index()
        {
            var userManager          = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            List <VmUsersList> model = new List <VmUsersList>();

            foreach (var item in context.Users)
            {
                VmUsersList user = new VmUsersList()
                {
                    userId   = item.Id,
                    UserName = item.UserName,
                    RoleUser = userManager.GetRoles(item.Id).Count() != 0 ? userManager.GetRoles(item.Id):null
                };
                model.Add(user);
            }
            ViewBag.RoleName = new SelectList(context.Roles, "Name", "Name");
            return(View(model));
        }