public async Task<ActionResult> UserRoles(SelectUserRolesViewModel model) { if (ModelState.IsValid) { var identityManager = new IdentityManager(); var user = this.ApplicationDbContext.Users.First(u => u.UserName == model.UserName); await identityManager.ClearUserRolesAsync(user.Id); foreach (var role in model.Roles) { if (role.Selected) { await identityManager.AddUserToRoleAsync(user.Id, role.RoleName); } } return RedirectToAction("index"); } return View(); }