public ActionResult EditUserRoles(EditUserRoles model) { try { if (ModelState.IsValid) { var user = UserManager.FindByEmail(model.Email); var oldRoleId = user.Roles.SingleOrDefault().RoleId; if (user != null) { if (oldRoleId != model.RoleId) { iur.UserId = user.Id; iur.RoleId = model.RoleId; UserManager.RemoveFromRole(user.Id, oldRoleId); UserManager.AddToRole(user.Id, model.RoleId); db.Entry(iur).State = EntityState.Modified; db.SaveChanges(); } } } return(View()); } catch (Exception ex) { log.Log(LogLevel.Error) .Exception(ex) .Message("Mensagem de log {0} parametro", 1).Write(); return(View()); } }
// GET: Role/Edit/5 public ActionResult Edit(string id) { var user = context.Users.FirstOrDefault(x => x.Id == id); if (user == null) { return(RedirectToAction("Index")); } else { var roles = new SelectList(context.Roles.Select(x => new EditRoleModel { Name = x.Name, Id = x.Id }), "Name", "Name"); var userRolesModel = new EditUserRoles { Roles = roles, UserId = id, UserName = user.UserName, HavingRoles = user.Roles }; return(View(userRolesModel)); } }
private void RoleManagementMenuItem_Click(object sender, RoutedEventArgs e) { EditUserRoles.Show(ModuleManager.Instance.Modules.Select(kv => kv.Value).ToList()); }