public DataTable QueryRoles(string userID) { using (TimePointScope scope = new TimePointScope()) { var allConditions = MergeConditionForRoleAndUser((WhereSqlClauseBuilder) new WhereSqlClauseBuilder().AppendItem("U.ID", userID)); string sql = roleAndUserSql + allConditions.ToSqlString(TSqlBuilder.Instance); return(DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]); } }
public int DisplaceUserInRole(string roleID, string userID, string[] displacingUserIDArray) { if (string.IsNullOrEmpty(userID)) { throw new ArgumentException("userID is required and cannot be empty", "userID"); } if (displacingUserIDArray == null) { throw new ArgumentNullException("displacingUserIDArray"); } bool userIsInTarget = false; int result = 0; HashSet <string> allKeys = new HashSet <string>(displacingUserIDArray); // 除重用 if (allKeys.Contains(userID)) { userIsInTarget = true; } displacingUserIDArray = allKeys.ToArray(); using (TimePointScope scope = new TimePointScope()) { SchemaObjectCollection loadedUsers = displacingUserIDArray.Length > 0 ? LoadObjects(displacingUserIDArray) : new SchemaObjectCollection(); SCUser sourceUser = userIsInTarget ? (SCUser)loadedUsers[userID] : (SCUser)PC.Adapters.SchemaObjectAdapter.Instance.Load(userID); if (sourceUser != null && sourceUser.Status == MCS.Library.SOA.DataObjects.Schemas.SchemaProperties.SchemaObjectStatus.Normal) { if (string.IsNullOrEmpty(roleID) == false) { SCRole role = (SCRole)PC.Adapters.SchemaObjectAdapter.Instance.Load(roleID); if (role != null && role.Status == MCS.Library.SOA.DataObjects.Schemas.SchemaProperties.SchemaObjectStatus.Normal) { result = DoDisplaceUserInRole(loadedUsers, sourceUser, role); } } else { var posibleRoleRelations = PC.Adapters.SCMemberRelationAdapter.Instance.LoadByMemberID(sourceUser.ID, "Roles", true, DateTime.MinValue); if (posibleRoleRelations.Count > 0) { var possibleRoles = LoadObjects(posibleRoleRelations.ToContainerIDArray()); using (System.Transactions.TransactionScope tran = TransactionScopeFactory.Create()) { bool allSuccess = true; foreach (SCRole r in possibleRoles) { if (DoDisplaceUserInRole(loadedUsers, sourceUser, r) == 0) { allSuccess = false; break; } } if (allSuccess) { tran.Complete(); result = 1; } else { result = 0; } } } } } } return(result); }