Exemplo n.º 1
0
        public ActionResult UserRoles(SelectUserRolesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var db = new ApplicationDbContext();
                var user = db.Users.First(m => m.UserName == model.UserName);
                var im = new IdentityManager();
                im.ClearUserRoles(user.Id);
                foreach (var role in model.Roles)
                {
                    if (role.Selected)
                    {
                        im.AddUserToRole(user.Id, role.RoleName);
                    }
                }

                return RedirectToAction("Index");
            }
            return View();
        }
Exemplo n.º 2
0
 public ActionResult UserRoles(string id)
 {
     var db = new ApplicationDbContext();
     var user = db.Users.First(m => m.UserName == id);
     var model = new SelectUserRolesViewModel(user);
     return View(model);
 }