public ActionResult Edit(SetRoleModel model) { if (ModelState.IsValid) { // Attempt to register the user try { var roles = Roles.GetRolesForUser(model.UserName); if (roles.Length > 0) { Roles.RemoveUserFromRoles(model.UserName, roles); } if (model.IsAdmin) { Roles.AddUserToRole(model.UserName, "Admin"); } if (model.IsEnvirolytic) { Roles.AddUserToRole(model.UserName, "Envirolytic"); } return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> DelUserRole(SetRoleModel model) { var result = await _userRoleService.DeleteAsync( item => model.UserIds.Contains(item.UserId) && item.RoleId == model.RoleId); return(Json(result)); }
public ActionResult SetRole(SetRoleModel model) { var result = new JsonModel(); User2RoleRepository.SaveList(model.UserIds, model.RoleIds); result.msg = "保存成功!"; result.code = JsonModelCode.Succ; return(Json(result)); }
public async Task <ActionResult> SetRole(long apartId) { var model = new SetRoleModel() { UserId = apartId, SelectedRoleIdList = await UserRole2ApartRepository.GetRoleIdListAsync(apartId), UserRoleList = await UserRoleRepository.GetListAsync() }; return(PartialView(model)); }
public async Task <IActionResult> SetUserRole(SetRoleModel dto) { var dtos = new List <Sys_UserRoleDto>(); foreach (int userId in dto.UserIds) { dtos.Add(new Sys_UserRoleDto { UserId = userId, RoleId = dto.RoleId }); } var result = await _userRoleService.AddAsync(dtos); return(Json(result)); }
public ActionResult ListUsers() { var users = Membership.GetAllUsers(); List <SetRoleModel> roleModels = new List <SetRoleModel>(); SetRoleModel roleModel; foreach (MembershipUser user in users) { roleModel = new SetRoleModel(); roleModel.UserName = user.UserName; if (Roles.IsUserInRole("Admin")) { roleModel.IsAdmin = true; } if (Roles.IsUserInRole("Envirolytic")) { roleModel.IsEnvirolytic = true; } roleModels.Add(roleModel); } return(View(roleModels)); }