Exemplo n.º 1
0
 /// <summary>
 /// ######### ########## ##### LDAP.
 /// </summary>
 private void InsertLDAPGroups(List <LdapGroup> ldapElements)
 {
     foreach (var ldapElement in ldapElements)
     {
         var entity     = new LDAPElement(CurrentUserConnection);
         var conditions = new Dictionary <string, object> {
             { "LDAPEntryId", ldapElement.Id },
             { "Type", (int)Core.DB.SysAdminUnitType.Team }
         };
         lock (_lockObject) {
             if (!entity.FetchFromDB(conditions))
             {
                 entity.SetDefColumnValues();
                 entity.SetColumnValue("Type", (int)Core.DB.SysAdminUnitType.Team);
                 entity.SetColumnValue("IsActive", true);
                 entity.SetColumnValue("LDAPEntryId", ldapElement.Id);
             }
             else if (entity.Name == ldapElement.Name && entity.LDAPEntryDN == ldapElement.Dn)
             {
                 continue;
             }
             entity.SetColumnValue("Name", ldapElement.Name);
             entity.SetColumnValue("LDAPEntryDN", ldapElement.Dn);
             entity.Save();
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// ######### ########## ############# LDAP.
        /// </summary>
        private void InsertLDAPUsers(List <LdapUser> ldapElements, Guid ldapGroupId)
        {
            var activeLdapElements = ldapElements.Where(item => item.IsActive).ToList();

            foreach (var ldapElement in activeLdapElements)
            {
                var entity     = new LDAPElement(CurrentUserConnection);
                var conditions = new Dictionary <string, object> {
                    { "LDAPEntryId", ldapElement.Id },
                    { "Type", (int)Core.DB.SysAdminUnitType.User }
                };
                lock (_lockObject) {
                    if (!entity.FetchFromDB(conditions))
                    {
                        entity.SetDefColumnValues();
                        entity.SetColumnValue("Type", (int)Core.DB.SysAdminUnitType.User);
                        entity.SetColumnValue("IsActive", true);
                        entity.SetColumnValue("LDAPEntryId", ldapElement.Id);
                    }
                    entity.SetColumnValue("Name", ldapElement.Name);
                    entity.SetColumnValue("FullName", ldapElement.FullName);
                    entity.SetColumnValue("Company", ldapElement.Company);
                    entity.SetColumnValue("Email", ldapElement.Email);
                    entity.SetColumnValue("Phone", ldapElement.Phone);
                    entity.SetColumnValue("JobTitle", ldapElement.JobTitle);
                    entity.SetColumnValue("LDAPEntryDN", ldapElement.Dn);
                    entity.Save();
                    Guid ldapUserId      = entity.PrimaryColumnValue;
                    var  esqLdapLElement = new EntitySchemaQuery(CurrentUserConnection.EntitySchemaManager, "LDAPUserInLDAPGroup");
                    esqLdapLElement.AddColumn("LDAPUser");
                    esqLdapLElement.Filters.Add(esqLdapLElement.CreateFilterWithParameters(
                                                    FilterComparisonType.Equal, "LDAPUser", ldapUserId));
                    esqLdapLElement.Filters.Add(esqLdapLElement.CreateFilterWithParameters(
                                                    FilterComparisonType.Equal, "LDAPGroup", ldapGroupId));
                    var collection = esqLdapLElement.GetEntityCollection(CurrentUserConnection);
                    if (collection.Count == 0)
                    {
                        var userInLDAPGroupEntity = new Terrasoft.Configuration.LDAPUserInLDAPGroup(CurrentUserConnection);
                        userInLDAPGroupEntity.SetDefColumnValues();
                        userInLDAPGroupEntity.SetColumnValue("LDAPUserId", ldapUserId);
                        userInLDAPGroupEntity.SetColumnValue("LDAPGroupId", ldapGroupId);
                        userInLDAPGroupEntity.Save();
                    }
                }
            }
        }