private static List <int> GetSwitchTargets(SiteSettings ss, int deptId) { var view = Views.GetBySession(ss); var where = view.Where(ss: ss, where : Rds.DeptsWhere().TenantId(Sessions.TenantId())); var join = ss.Join(); var switchTargets = Rds.ExecuteScalar_int(statements: Rds.SelectDepts( column: Rds.DeptsColumn().DeptsCount(), join: join, where : where)) <= Parameters.General.SwitchTargetsLimit ? Rds.ExecuteTable(statements: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), join: join, where : where, orderBy: view.OrderBy(ss).Depts_UpdatedTime(SqlOrderBy.Types.desc))) .AsEnumerable() .Select(o => o["DeptId"].ToInt()) .ToList() : new List <int>(); if (!switchTargets.Contains(deptId)) { switchTargets.Add(deptId); } return(switchTargets); }
private static void UpdateOrInsert( string loginId, DirectoryEntry entry, ParameterAccessor.Parts.Ldap ldap) { var deptCode = entry.Property(ldap.LdapDeptCode, ldap.LdapDeptCodePattern); var deptName = entry.Property(ldap.LdapDeptName, ldap.LdapDeptNamePattern); var deptExists = !deptCode.IsNullOrEmpty() && !deptName.IsNullOrEmpty(); var userCode = entry.Property(ldap.LdapUserCode, ldap.LdapUserCodePattern); var name = Name(loginId, entry, ldap); var mailAddress = entry.Property(ldap.LdapMailAddress, ldap.LdapMailAddressPattern); var statements = new List <SqlStatement>(); if (deptExists) { statements.Add(Rds.UpdateOrInsertDepts( param: Rds.DeptsParam() .TenantId(ldap.LdapTenantId) .DeptCode(deptCode) .DeptName(deptName), where : Rds.DeptsWhere().DeptCode(deptCode))); } statements.Add(Rds.UpdateOrInsertUsers( param: Rds.UsersParam() .TenantId(ldap.LdapTenantId) .LoginId(loginId) .UserCode(userCode) .Name(name) .DeptId( sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode)), _using: deptExists) .DeptId(0, _using: !deptExists), where : Rds.UsersWhere().LoginId(loginId))); if (!mailAddress.IsNullOrEmpty()) { statements.Add(Rds.PhysicalDeleteMailAddresses( where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))))); statements.Add(Rds.InsertMailAddresses( param: Rds.MailAddressesParam() .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))) .OwnerType("Users") .MailAddress(mailAddress))); } statements.Add(StatusUtilities.UpdateStatus( StatusUtilities.Types.DeptsUpdated, tenantId: ldap.LdapTenantId)); statements.Add(StatusUtilities.UpdateStatus( StatusUtilities.Types.UsersUpdated, tenantId: ldap.LdapTenantId)); Rds.ExecuteNonQuery( transactional: true, statements: statements.ToArray()); }
private static SqlColumnCollection DefaultSqlColumns(SiteSettings ss) { var sqlColumnCollection = Rds.DeptsColumn(); new List <string> { "DeptId", "Creator", "Updator" } .Concat(ss.IncludedColumns()) .Concat(ss.GetUseSearchLinks().Select(o => o.ColumnName)) .Concat(ss.TitleColumns) .Distinct().ForEach(column => sqlColumnCollection.DeptsColumn(column)); return(sqlColumnCollection); }
private static SqlColumnCollection GridSqlColumnCollection(SiteSettings ss) { var sqlColumnCollection = Rds.DeptsColumn(); new List <string> { "DeptId", "Creator", "Updator" } .Concat(ss.GridColumns) .Concat(ss.IncludedColumns()) .Concat(ss.TitleColumns) .Distinct().ForEach(column => sqlColumnCollection.DeptsColumn(column)); return(sqlColumnCollection); }
/// <summary> /// Fixed: /// </summary> private static Dictionary <string, ControlData> SelectableMembers() { var data = new Dictionary <string, ControlData>(); var searchText = Forms.Data("SearchMemberText"); if (!searchText.IsNullOrEmpty()) { var currentMembers = Forms.List("CurrentMembersAll"); Rds.ExecuteTable(statements: new SqlStatement[] { Rds.SelectDepts( column: Rds.DeptsColumn() .DeptId() .Add("0 as [UserId]"), where : Rds.DeptsWhere() .TenantId(Sessions.TenantId()) .DeptId_In( currentMembers? .Where(o => o.StartsWith("Dept,")) .Select(o => o.Split_2nd().ToInt()), negative: true) .SqlWhereLike( searchText, Rds.Depts_DeptId_WhereLike(), Rds.Depts_DeptCode_WhereLike(), Rds.Depts_DeptName_WhereLike())), Rds.SelectUsers( unionType: Sqls.UnionTypes.Union, column: Rds.UsersColumn() .Add("0 as [DeptId]") .UserId(), where : Rds.UsersWhere() .TenantId(Sessions.TenantId()) .UserId_In( currentMembers? .Where(o => o.StartsWith("User,")) .Select(o => o.Split_2nd().ToInt()), negative: true) .SqlWhereLike( searchText, Rds.Users_LoginId_WhereLike(), Rds.Users_UserId_WhereLike(), Rds.Users_Name_WhereLike())) }) .AsEnumerable() .ForEach(dataRow => data.AddMember(dataRow)); } return(data); }
/// <summary> /// Fixed: /// </summary> public bool InTenant(IContext context) { var depts = this.Where(o => o.DeptId > 0).Select(o => o.DeptId); var groups = this.Where(o => o.GroupId > 0).Select(o => o.GroupId); var users = this.Where(o => o.UserId > 0).Select(o => o.UserId); var dataSet = Rds.ExecuteDataSet( context: context, statements: new SqlStatement[] { Rds.SelectDepts( dataTableName: "Depts", column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere() .TenantId(context.TenantId) .DeptId_In(depts)), Rds.SelectGroups( dataTableName: "Groups", column: Rds.GroupsColumn().GroupId(), where : Rds.GroupsWhere() .TenantId(context.TenantId) .GroupId_In(groups)), Rds.SelectUsers( dataTableName: "Users", column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere() .TenantId(context.TenantId) .UserId_In(users)) }); var deptRecords = dataSet.Tables["Depts"] .AsEnumerable() .Select(p => p["DeptId"].ToInt()); var groupRecords = dataSet.Tables["Groups"] .AsEnumerable() .Select(p => p["GroupId"].ToInt()); var userRecords = dataSet.Tables["Users"] .AsEnumerable() .Select(p => p["UserId"].ToInt()); return (depts.All(o => deptRecords.Contains(o)) || groups.All(o => groupRecords.Contains(o)) || users.All(o => userRecords.Contains(o))); }
private static DataTable SiteDeptDataTable(Context context, long siteId) { var deptRaw = "[Depts].[DeptId] and [Depts].[DeptId]>0"; return(Rds.ExecuteTable( context: context, statements: Rds.SelectDepts( distinct: true, column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere() .TenantId(context.TenantId) .Add( subLeft: Rds.SelectPermissions( column: Rds.PermissionsColumn() .PermissionType(function: Sqls.Functions.Max), where : Rds.PermissionsWhere() .ReferenceId(siteId) .DeptId(raw: deptRaw)), _operator: ">0")))); }
private static void UpdateOrInsert(string loginId, DirectoryEntry entry) { var deptCode = entry.Property(Parameters.Authentication.LdapDeptCode); var deptName = entry.Property(Parameters.Authentication.LdapDeptName); var userCode = entry.Property(Parameters.Authentication.LdapUserCode); var firstName = entry.Property(Parameters.Authentication.LdapFirstName); var lastName = entry.Property(Parameters.Authentication.LdapLastName); var mailAddress = entry.Property(Parameters.Authentication.LdapMailAddress); Rds.ExecuteNonQuery(statements: new SqlStatement[] { Rds.UpdateOrInsertDepts( param: Rds.DeptsParam() .TenantId(Parameters.Authentication.LdapTenantId) .DeptCode(deptCode) .DeptName(deptName), where : Rds.DeptsWhere().DeptCode(deptCode)), Rds.UpdateOrInsertUsers( param: Rds.UsersParam() .TenantId(Parameters.Authentication.LdapTenantId) .LoginId(loginId) .UserCode(userCode) .Name(lastName + " " + firstName) .DeptId(sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode))), where : Rds.UsersWhere().LoginId(loginId)), Rds.UpdateOrInsertMailAddresses( param: Rds.MailAddressesParam() .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))) .OwnerType("Users") .MailAddress(mailAddress), where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId)))) }); }
public static int ConvertedDeptId( Context context, PermissionIdList permissionIdList, int deptId) { var deptCode = permissionIdList?.DeptIdList .FirstOrDefault(x => x.DeptId == deptId) ?.DeptCode; return(!deptCode.IsNullOrEmpty() ? Rds.ExecuteTable( context: context, statements: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere() .TenantId(context.TenantId) .DeptCode(deptCode))) .AsEnumerable() .FirstOrDefault() ?.Int("DeptId") ?? 0 : 0); }
public static void Reflesh(bool force = false) { var tenantId = Sessions.TenantId(); if (!TenantCaches.ContainsKey(tenantId)) { try { TenantCaches.Add(tenantId, new TenantCache(tenantId)); } catch (Exception) { } } var tenantCache = TenantCaches.Get(tenantId); var monitor = tenantCache.GetUpdateMonitor(); if (monitor.DeptsUpdated || monitor.UsersUpdated || force) { var dataSet = Rds.ExecuteDataSet(statements: new SqlStatement[] { Rds.SelectDepts( dataTableName: "Depts", column: Rds.DeptsColumn() .TenantId() .DeptId() .DeptName(), where : Rds.DeptsWhere().TenantId(tenantId), _using: monitor.DeptsUpdated || force), Rds.SelectUsers( dataTableName: "Users", column: Rds.UsersColumn() .TenantId() .UserId() .DeptId() .LoginId() .Name() .TenantManager() .ServiceManager(), where : Rds.UsersWhere().TenantId(tenantId), _using: monitor.UsersUpdated || force) }); if (monitor.DeptsUpdated || force) { tenantCache.DeptHash = dataSet.Tables["Depts"] .AsEnumerable() .ToDictionary( dataRow => dataRow["DeptId"].ToInt(), dataRow => new Dept(dataRow)); } if (monitor.UsersUpdated || force) { tenantCache.UserHash = dataSet.Tables["Users"] .AsEnumerable() .ToDictionary( dataRow => dataRow["UserId"].ToInt(), dataRow => new User(dataRow)); } } if (monitor.PermissionsUpdated || monitor.GroupsUpdated || monitor.UsersUpdated || force) { tenantCache.SiteUserHash = new Dictionary <long, List <int> >(); } if (monitor.SitesUpdated || force) { tenantCache.SiteMenu = new SiteMenu(tenantId); } if (monitor.Updated || force) { monitor.Update(); } }
public static void Reflesh(Context context, bool force = false) { if (context.TenantId == 0) { return; } var tenantCache = TenantCaches.Get(context.TenantId); var monitor = tenantCache.GetUpdateMonitor(context: context); if (monitor.DeptsUpdated || monitor.UsersUpdated || force) { var dataSet = Rds.ExecuteDataSet( context: context, statements: new SqlStatement[] { Rds.SelectDepts( dataTableName: "Depts", column: Rds.DeptsColumn() .TenantId() .DeptId() .DeptCode() .DeptName(), where : Rds.DeptsWhere().TenantId(context.TenantId), _using: monitor.DeptsUpdated || force), Rds.SelectUsers( dataTableName: "Users", column: Rds.UsersColumn() .TenantId() .UserId() .DeptId() .LoginId() .Name() .TenantManager() .ServiceManager() .Disabled(), where : Rds.UsersWhere().TenantId(context.TenantId), _using: monitor.UsersUpdated || force) }); if (monitor.DeptsUpdated || force) { tenantCache.DeptHash = dataSet.Tables["Depts"] .AsEnumerable() .ToDictionary( dataRow => dataRow.Int("DeptId"), dataRow => new Dept(dataRow)); } if (monitor.UsersUpdated || force) { tenantCache.UserHash = dataSet.Tables["Users"] .AsEnumerable() .ToDictionary( dataRow => dataRow.Int("UserId"), dataRow => new User( context: context, dataRow: dataRow)); } } if (monitor.PermissionsUpdated || monitor.GroupsUpdated || monitor.UsersUpdated || force) { tenantCache.SiteDeptHash = new Dictionary <long, List <int> >(); tenantCache.SiteUserHash = new Dictionary <long, List <int> >(); tenantCache.SiteGroupHash = new Dictionary <long, List <int> >(); } if (monitor.SitesUpdated || force) { tenantCache.SiteMenu = new SiteMenu(context: context); } if (monitor.Updated || force) { monitor.Update(); } }
/// <summary> /// Fixed: /// </summary> private static Dictionary <string, ControlData> SelectableMembers() { var data = new Dictionary <string, ControlData>(); var searchText = Forms.Data("SearchMemberText"); if (!searchText.IsNullOrEmpty()) { var currentMembers = Forms.List("CurrentMembersAll"); Rds.ExecuteTable(statements: new SqlStatement[] { Rds.SelectDepts( column: Rds.DeptsColumn() .DeptId() .DeptCode() .Add("0 as [UserId]") .Add("'' as [UserCode]") .Add("0 as [IsUser]"), where : Rds.DeptsWhere() .TenantId(Sessions.TenantId()) .DeptId_In( currentMembers? .Where(o => o.StartsWith("Dept,")) .Select(o => o.Split_2nd().ToInt()), negative: true) .SqlWhereLike( searchText, Rds.Depts_DeptCode_WhereLike(), Rds.Depts_DeptName_WhereLike())), Rds.SelectUsers( unionType: Sqls.UnionTypes.Union, column: Rds.UsersColumn() .Add("0 as [DeptId]") .Add("'' as [DeptCode]") .UserId() .UserCode() .Add("1 as [IsUser]"), join: Rds.UsersJoin() .Add(new SqlJoin( tableBracket: "[Depts]", joinType: SqlJoin.JoinTypes.LeftOuter, joinExpression: "[Users].[DeptId]=[Depts].[DeptId]")), where : Rds.UsersWhere() .TenantId(Sessions.TenantId()) .UserId_In( currentMembers? .Where(o => o.StartsWith("User,")) .Select(o => o.Split_2nd().ToInt()), negative: true) .SqlWhereLike( searchText, Rds.Users_LoginId_WhereLike(), Rds.Users_Name_WhereLike(), Rds.Users_UserCode_WhereLike(), Rds.Users_Body_WhereLike(), Rds.Depts_DeptCode_WhereLike(), Rds.Depts_DeptName_WhereLike(), Rds.Depts_Body_WhereLike()) .Users_Disabled(0)) }) .AsEnumerable() .OrderBy(o => o["IsUser"]) .ThenBy(o => o["DeptCode"]) .ThenBy(o => o["DeptId"]) .ThenBy(o => o["UserCode"]) .ForEach(dataRow => data.AddMember(dataRow)); } return(data); }
public static void UpdateOrInsert( Context context, int tenantId, string loginId, string name, string mailAddress, DateTime synchronizedTime, SamlAttributes attributes) { var deptCode = attributes[nameof(UserModel.DeptCode)]; var deptName = attributes[nameof(UserModel.Dept)]; var deptSettings = !deptCode.IsNullOrEmpty() && !deptName.IsNullOrEmpty(); var isEmptyDeptCode = deptCode == string.Empty; var user = new UserModel().Get( context: context, ss: null, where: Rds.UsersWhere() .TenantId(tenantId) .LoginId(loginId) .Name(name) .TenantManager( attributes.TenantManager, _using: attributes[nameof(UserModel.TenantManager)] != null) .FirstName( attributes[nameof(UserModel.FirstName)], _using: attributes[nameof(UserModel.FirstName)] != null) .LastName( attributes[nameof(UserModel.LastName)], _using: attributes[nameof(UserModel.LastName)] != null) .FirstAndLastNameOrder( attributes[nameof(UserModel.FirstAndLastNameOrder)], _using: attributes[nameof(UserModel.FirstAndLastNameOrder)] != null) .UserCode( attributes[nameof(UserModel.UserCode)], _using: attributes[nameof(UserModel.UserCode)] != null) .Birthday( attributes[nameof(UserModel.Birthday)], _using: attributes[nameof(UserModel.Birthday)] != null) .Gender( attributes[nameof(UserModel.Gender)], _using: attributes[nameof(UserModel.Gender)] != null) .Language( attributes[nameof(UserModel.Language)], _using: attributes[nameof(UserModel.Language)] != null) .TimeZone( attributes[nameof(UserModel.TimeZone)], _using: attributes[nameof(UserModel.TimeZone)] != null) .DeptId( sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode)), _using: deptSettings) .Body( attributes[nameof(UserModel.Body)], _using: attributes[nameof(UserModel.Body)] != null)); if (!isEmptyDeptCode && user.AccessStatus == Databases.AccessStatuses.Selected) { if (mailAddress.IsNullOrEmpty()) { return; } var addressCount = Rds.ExecuteScalar_long( context: context, statements: new[] { Rds.SelectMailAddresses( dataTableName: "Count", column: Rds.MailAddressesColumn().MailAddressesCount(), where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))) .MailAddress(mailAddress)) }); if (addressCount > 0) { return; } } var statements = new List <SqlStatement>(); if (deptSettings) { statements.Add(Rds.UpdateOrInsertDepts( param: Rds.DeptsParam() .TenantId(tenantId) .DeptCode(deptCode) .DeptName(deptName), where : Rds.DeptsWhere().DeptCode(deptCode))); } var param = Rds.UsersParam() .TenantId(tenantId) .LoginId(loginId) .Name(name) .TenantManager(attributes.TenantManager, _using: attributes[nameof(UserModel.TenantManager)] != null) .SynchronizedTime(synchronizedTime) .FirstName( attributes[nameof(UserModel.FirstName)], _using: attributes[nameof(UserModel.FirstName)] != null) .LastName( attributes[nameof(UserModel.LastName)], _using: attributes[nameof(UserModel.LastName)] != null) .FirstAndLastNameOrder( attributes[nameof(UserModel.FirstAndLastNameOrder)], _using: attributes[nameof(UserModel.FirstAndLastNameOrder)] != null) .UserCode( attributes[nameof(UserModel.UserCode)], _using: attributes[nameof(UserModel.UserCode)] != null) .DeptId( sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode)), _using: deptSettings) .DeptId(0, _using: isEmptyDeptCode) .Birthday( attributes[nameof(UserModel.Birthday)], _using: attributes[nameof(UserModel.Birthday)] != null) .Gender( attributes[nameof(UserModel.Gender)], _using: attributes[nameof(UserModel.Gender)] != null) .Language( attributes[nameof(UserModel.Language)], _using: attributes[nameof(UserModel.Language)] != null) .TimeZone( attributes[nameof(UserModel.TimeZone)], _using: attributes[nameof(UserModel.TimeZone)] != null) .Body( attributes[nameof(UserModel.Body)], _using: attributes[nameof(UserModel.Body)] != null); statements.Add(Rds.UpdateOrInsertUsers( param: param, where : Rds.UsersWhere().TenantId(tenantId).LoginId(loginId), addUpdatorParam: true, addUpdatedTimeParam: true)); if (!mailAddress.IsNullOrEmpty()) { statements.Add(Rds.PhysicalDeleteMailAddresses( where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))))); statements.Add(Rds.InsertMailAddresses( param: Rds.MailAddressesParam() .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))) .OwnerType("Users") .MailAddress(mailAddress))); } statements.Add(StatusUtilities.UpdateStatus( tenantId: tenantId, type: StatusUtilities.Types.DeptsUpdated)); statements.Add(StatusUtilities.UpdateStatus( tenantId: tenantId, type: StatusUtilities.Types.UsersUpdated)); Rds.ExecuteNonQuery( context: context, transactional: true, statements: statements.ToArray()); }
private static void UpdateOrInsert( Context context, string loginId, string deptCode, string deptName, string userCode, string name, string mailAddress, List <KeyValuePair <LdapExtendedAttribute, string> > attributes, ParameterAccessor.Parts.Ldap ldap, DateTime synchronizedTime) { var deptExists = !deptCode.IsNullOrEmpty() && !deptName.IsNullOrEmpty(); var deptSettings = !ldap.LdapDeptCode.IsNullOrEmpty() && !ldap.LdapDeptName.IsNullOrEmpty(); var statements = new List <SqlStatement>(); if (deptExists) { statements.Add(Rds.UpdateOrInsertDepts( param: Rds.DeptsParam() .TenantId(ldap.LdapTenantId) .DeptCode(deptCode) .DeptName(deptName), where : Rds.DeptsWhere().DeptCode(deptCode))); } var exists = Rds.ExecuteScalar_int( context: context, statements: Rds.SelectUsers( column: Rds.UsersColumn().UsersCount(), where : Rds.UsersWhere().LoginId( value: context.Sqls.EscapeValue(loginId), _operator: context.Sqls.LikeWithEscape))) == 1; var param = Rds.UsersParam() .TenantId(ldap.LdapTenantId) .LoginId(loginId, _using: !exists) .UserCode(userCode) .Name(name) .DeptId( sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode)), _using: deptExists) .DeptId(0, _using: deptSettings && !deptExists) .LdapSearchRoot(ldap.LdapSearchRoot) .SynchronizedTime(synchronizedTime); attributes?.ForEach(attributeAndName => param.Add( $"\"Users\".\"{attributeAndName.Key.ColumnName}\"", attributeAndName.Key.ColumnName, attributeAndName.Value)); statements.Add(Rds.UpdateOrInsertUsers( param: param, where : Rds.UsersWhere().LoginId( value: context.Sqls.EscapeValue(loginId), _operator: context.Sqls.LikeWithEscape), addUpdatorParam: false, addUpdatedTimeParam: false)); if (!mailAddress.IsNullOrEmpty()) { statements.Add(Rds.PhysicalDeleteMailAddresses( where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId( value: context.Sqls.EscapeValue(loginId), _operator: context.Sqls.LikeWithEscape))))); statements.Add(Rds.InsertMailAddresses( param: Rds.MailAddressesParam() .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId( value: context.Sqls.EscapeValue(loginId), _operator: context.Sqls.LikeWithEscape))) .OwnerType("Users") .MailAddress(mailAddress))); } var ss = new SiteSettings(); statements.Add(StatusUtilities.UpdateStatus( tenantId: ldap.LdapTenantId, type: StatusUtilities.Types.DeptsUpdated)); statements.Add(StatusUtilities.UpdateStatus( tenantId: ldap.LdapTenantId, type: StatusUtilities.Types.UsersUpdated)); Repository.ExecuteNonQuery( context: context, transactional: true, statements: statements.ToArray()); }
private static void UpdateOrInsert( Context context, string loginId, SearchResult result, ParameterAccessor.Parts.Ldap ldap, DateTime synchronizedTime) { var deptCode = result.Property( context: context, name: ldap.LdapDeptCode, pattern: ldap.LdapDeptCodePattern); var deptName = result.Property( context: context, name: ldap.LdapDeptName, pattern: ldap.LdapDeptNamePattern); var deptExists = !deptCode.IsNullOrEmpty() && !deptName.IsNullOrEmpty(); var deptSettings = !ldap.LdapDeptCode.IsNullOrEmpty() && !ldap.LdapDeptName.IsNullOrEmpty(); var userCode = result.Property( context: context, name: ldap.LdapUserCode, pattern: ldap.LdapUserCodePattern); var name = Name( context: context, loginId: loginId, result: result, ldap: ldap); var mailAddress = result.Property( context: context, name: ldap.LdapMailAddress, pattern: ldap.LdapMailAddressPattern); var statements = new List <SqlStatement>(); if (deptExists) { statements.Add(Rds.UpdateOrInsertDepts( param: Rds.DeptsParam() .TenantId(ldap.LdapTenantId) .DeptCode(deptCode) .DeptName(deptName), where : Rds.DeptsWhere().DeptCode(deptCode))); } var param = Rds.UsersParam() .TenantId(ldap.LdapTenantId) .LoginId(loginId) .UserCode(userCode) .Name(name) .DeptId( sub: Rds.SelectDepts( column: Rds.DeptsColumn().DeptId(), where : Rds.DeptsWhere().DeptCode(deptCode)), _using: deptExists) .DeptId(0, _using: deptSettings && !deptExists) .LdapSearchRoot(ldap.LdapSearchRoot) .SynchronizedTime(synchronizedTime); ldap.LdapExtendedAttributes?.ForEach(attribute => param.Add( $"[Users].[{attribute.ColumnName}]", attribute.ColumnName, result.Property( context: context, name: attribute.Name, pattern: attribute.Pattern))); statements.Add(Rds.UpdateOrInsertUsers( param: param, where : Rds.UsersWhere().LoginId(loginId), addUpdatorParam: false, addUpdatedTimeParam: false)); if (!mailAddress.IsNullOrEmpty()) { statements.Add(Rds.PhysicalDeleteMailAddresses( where : Rds.MailAddressesWhere() .OwnerType("Users") .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))))); statements.Add(Rds.InsertMailAddresses( param: Rds.MailAddressesParam() .OwnerId(sub: Rds.SelectUsers( column: Rds.UsersColumn().UserId(), where : Rds.UsersWhere().LoginId(loginId))) .OwnerType("Users") .MailAddress(mailAddress))); } var ss = new SiteSettings(); statements.Add(StatusUtilities.UpdateStatus( tenantId: ldap.LdapTenantId, type: StatusUtilities.Types.DeptsUpdated)); statements.Add(StatusUtilities.UpdateStatus( tenantId: ldap.LdapTenantId, type: StatusUtilities.Types.UsersUpdated)); Rds.ExecuteNonQuery( context: context, transactional: true, statements: statements.ToArray()); }
private void Add( Context context, List <PackageSiteModel> sites, List <PackagePermissionModel> packagePermissionModels) { var deptIds = new HashSet <int>(); var groupIds = new HashSet <int>(); var userIds = new HashSet <int>(); foreach (var packagePermissionModel in packagePermissionModels) { foreach (var permission in packagePermissionModel.Permissions) { if (permission.DeptId > 0 && !deptIds.Contains(permission.DeptId)) { deptIds.Add(permission.DeptId); } if (permission.GroupId > 0 && !groupIds.Contains(permission.GroupId)) { groupIds.Add(permission.GroupId); } if (permission.UserId > 0 && !userIds.Contains(permission.UserId)) { userIds.Add(permission.UserId); } } } foreach (var packageSiteModel in sites) { foreach (var cca in packageSiteModel.SiteSettings.CreateColumnAccessControls) { foreach (var dept in cca.Depts ?? new List <int>() { 0 }) { deptIds.Add(dept); } foreach (var group in cca.Groups ?? new List <int>() { 0 }) { groupIds.Add(group); } foreach (var user in cca.Users ?? new List <int>() { 0 }) { userIds.Add(user); } } foreach (var rca in packageSiteModel.SiteSettings.ReadColumnAccessControls) { foreach (var dept in rca.Depts ?? new List <int>() { 0 }) { deptIds.Add(dept); } foreach (var group in rca.Groups ?? new List <int>() { 0 }) { groupIds.Add(group); } foreach (var user in rca.Users ?? new List <int>() { 0 }) { userIds.Add(user); } } foreach (var uca in packageSiteModel.SiteSettings.UpdateColumnAccessControls) { foreach (var dept in uca.Depts ?? new List <int>() { 0 }) { deptIds.Add(dept); } foreach (var group in uca.Groups ?? new List <int>() { 0 }) { groupIds.Add(group); } foreach (var user in uca.Users ?? new List <int>() { 0 }) { userIds.Add(user); } } } if (deptIds.Any()) { var deptTable = Rds.ExecuteTable( context: context, statements: Rds.SelectDepts( column: Rds.DeptsColumn() .DeptId() .DeptCode(), where : Rds.DeptsWhere() .DeptId_In(deptIds.Where(o => o != 0)))); foreach (DataRow data in deptTable.Rows) { DeptIdList.Add( new DeptIdHash() { DeptId = data[0].ToInt(), DeptCode = data[1].ToString() }); } } if (groupIds.Count() > 0) { var groupTable = Rds.ExecuteTable( context: context, statements: Rds.SelectGroups( column: Rds.GroupsColumn() .GroupId() .GroupName(), where : Rds.GroupsWhere() .GroupId_In( value: groupIds.Where(o => o != 0)))); foreach (DataRow dataRow in groupTable.Rows) { GroupIdList.Add( new GroupIdHash() { GroupId = dataRow[0].ToInt(), GroupName = dataRow[1].ToString() }); } } if (userIds.Count() > 0) { var userTable = Rds.ExecuteTable( context: context, statements: Rds.SelectUsers( column: Rds.UsersColumn() .UserId() .LoginId(), where : Rds.UsersWhere() .UserId_In( value: userIds.Where(o => o != 0)))); foreach (DataRow dataRow in userTable.Rows) { UserIdList.Add( new UserIdHash() { UserId = dataRow[0].ToInt(), LoginId = dataRow[1].ToString() }); } } }