Beispiel #1
0
        public ActionResult AddUserToRole(ModelAddToRole model)
        {
            var email = model.Email;
            var user  = UserManager.FindByEmail(model.Email);

            if (user == null)
            {
                throw new HttpException(404, "There is no user with email: " + model.Email);
            }

            UserManager.AddToRole(user.Id, model.selectedRole);
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public ActionResult AddUserToRole()
        {
            ModelAddToRole model = new ModelAddToRole();

            model.roles = new List <string>()
            {
                RoleNames.ADMIN, RoleNames.USER
            };

            // have them just to enter the roles in db for the first time
            // then dont use them
            //var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
            //RoleManager.Create(new IdentityRole(RoleNames.ADMIN));
            //RoleManager.Create(new IdentityRole(RoleNames.USER));

            return(View(model));
        }