public ActionResult UserRoles(SelectUserRolesViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new ApplicationDbContext())
         {
             var idManager = new IdentityManager();
             var user = db.Users.First(u => u.UserName == model.UserName);
             idManager.ClearUserRoles(user.Id);
             foreach (var role in model.Roles)
             {
                 if (role.Selected)
                     idManager.AddUserToRole(user.Id, role.RoleName);
             }
             return RedirectToAction("Index");
         }
     }
     // If we got this far, something failed, redisplay form
     return View(model);
 }
 public ActionResult UserRoles(string id)
 {
     if (id == null) return View("Error");
     using (var db = new ApplicationDbContext())
     {
         var user = db.Users.First(u => u.UserName == id);
         var model = new SelectUserRolesViewModel(user);
         return View(model);
     }
 }