public NormalResult AddUserListToRole(AddUserListToRoleArgs args) { using (Entities db = new Entities()) { Role role = db.Role.FirstOrDefault(r => r.id == args.RoleId); if (role == null) { return(new NormalResult("指定的角色不存在。")); } foreach (var userId in args.UserIdArray) { User user = role.User.FirstOrDefault(u => u.id == userId); if (user != null) { continue; } user = db.User.FirstOrDefault(u => u.id == userId); if (user == null) { return(new NormalResult("指定的用户不存在。")); } role.User.Add(user); } db.SaveChanges(); } return(new NormalResult()); }
public ActionResult AddUserListToRole() { AddUserListToRoleArgs args = RequestArgs <AddUserListToRoleArgs>(); if (args == null) { return(FailedResult("参数无效。")); } NormalResult result = _roleManager.AddUserListToRole(args); return(ApiResult(result.Successful, result.Message)); }