Пример #1
0
        public ActionResult ManageUserRoles(UserViewModel model)
        {
            var user = _context.Users.FirstOrDefault(u => u.UserName.Equals(model.UserName, StringComparison.CurrentCultureIgnoreCase));
            var um   = new Microsoft.AspNet.Identity.UserManager <IdentityUser>(new Microsoft.AspNet.Identity.EntityFramework.UserStore <IdentityUser>(_context));

            um.RemoveFromRole(user.Id, Helpers.Constants.Roles.Applicant);
            um.RemoveFromRole(user.Id, Helpers.Constants.Roles.Admin);
            um.RemoveFromRole(user.Id, Helpers.Constants.Roles.Staff);
            var idResult = um.AddToRole(user.Id, model.RoleName);

            model = GetUserViewModel(model.UserName);

            return(View("ManageUserRoles", model));
        }
        public void RemoveUserRole(string id, string role)
        {
            UserStore<ApplicationUser> userStore = new UserStore<ApplicationUser>(db);
            Microsoft.AspNet.Identity.UserManager<ApplicationUser> userManager = new Microsoft.AspNet.Identity.UserManager<ApplicationUser>(userStore);
            //var oldRole = System.Web.Security.Roles.GetRolesForUser().Single();
            //var account = new AccountController();
            //var oldRole = account.UserManager.GetRoles(id);

            userManager.RemoveFromRole(id, role);
            db.SaveChanges();
            //return userManager;
        }