public ActionResult UserRoles(SelectUserRolesViewModel model) { if (ModelState.IsValid) { var user = context.Users.First(u => u.UserName == model.UserName); foreach (var role in context.Roles) { UserManager.RemoveFromRoleAsync(user.Id, role.Name); } foreach (var role in model.Roles) { if (role.Selected) { UserManager.AddToRole(user.Id, role.RoleName); } } return RedirectToAction("Index"); } return View(); }
public ActionResult UserRoles(string userId) { //context = new PhotoDBContext(); if(string.IsNullOrEmpty(userId) == false) { var user = context.Users.FirstOrDefault(u => u.UserName == userId); if(user == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var model = new SelectUserRolesViewModel(user); return View(model); } return RedirectToAction("Index", "Home"); }