/// <summary> /// 新增或更改角色的用户 /// </summary> /// <param name="userList"></param> /// <param name="roleId"></param> /// <param name="len"></param> /// <returns></returns> public string CreateUserRole(List <SysUserModel> userList, string roleId, int len) { List <SysUserRoleModel> list = userRoleBLL.GetByRoleId(roleId); //去除已有的不需更改的记录 for (int i = 0; i < len; i++) { for (int j = 0; j < list.Count; j++) { if (userList[i].UserId == list[j].UserId) { userList.Remove(userList[i]); list.Remove(list[j]); i--; len--; break; } } if (userList.Count == 0) { break; } } if (list.Count != 0) { foreach (var a in list) { if (!userRoleBLL.Delete(a.Id)) { var json = js.Serialize(new { flag = false }); return(json); } } } if (userList.Count != 0) { foreach (var a in userList) { SysUserRoleModel userRoleModel = new SysUserRoleModel(); userRoleModel.Id = ResultHelper.NewId; userRoleModel.UserId = a.UserId; userRoleModel.RoleId = roleId; if (!userRoleBLL.Create(userRoleModel)) { var json = js.Serialize(new { flag = false }); return(json); } } var jsondata = js.Serialize(new { flag = true }); return(jsondata); } else if (list.Count == 0) { var jsondata = js.Serialize(new { flag = false }); return(jsondata); } else { var jsondata = js.Serialize(new { flag = true }); return(jsondata); } }