コード例 #1
0
        public ActionResult Details(string location, string department)
        {
            LDAPSearchObject search = new LDAPSearchObject();

            search.AND.Add("company", "Vision Integrated Graphics");
            search.AND.Add("physicalDeliveryOfficeName", location + "*");

            if (!string.IsNullOrEmpty(department))
            {
                search.AND.Add("department", department);
            }
            else
            {
                search.AND.Add("department", "*");
            }

            search.AND.Add("objectClass", "user");

            List <Contact> people = findContacts(search);

            search.Clear();
            search.AND.Add("physicalDeliveryOfficeName", location + "*");
            search.AND.Add("objectClass", "contact");

            List <Contact> contacts = findContacts(search);

            ViewModelFacilityDetail view = new ViewModelFacilityDetail();

            view.people   = people.OrderBy(o => o.DisplayName).ToList();
            view.contacts = contacts.OrderBy(o => o.DisplayName).ToList();

            search.Clear();

            search.AND.Add("company", "Vision Integrated Properties");
            search.AND.Add("title", "building");
            search.AND.Add("description", location + "*");
            search.AND.Add("objectClass", "contact");

            view.facility = findContact(search);
            return(View(view));
        }
コード例 #2
0
        public ActionResult Index()
        {
            ViewModelDepartmentIndex view   = new ViewModelDepartmentIndex();
            LDAPSearchObject         search = new LDAPSearchObject();

            search.AND.Add("company", "Vision Integrated Graphics");
            search.AND.Add("department", "*");

            List <Contact>       people      = findContacts(search);
            IEnumerable <string> departments = people.Select(x => x.Department).Distinct();

            Dictionary <string, int> viewObj = new Dictionary <string, int>();

            foreach (var department in departments)
            {
                viewObj.Add(department, people.Count(x => x.Department == department));
            }

            view.departments = viewObj;

            return(View(view));
        }
コード例 #3
0
        public Contact findContact(LDAPSearchObject search)
        {
            DirectoryEntry entry = new DirectoryEntry(search.root);
            Contact        p     = new Contact();

            using (DirectorySearcher ds = new DirectorySearcher(entry))
            {
                ds.Filter = search.filter();

                foreach (string a in search.LoadAttributes)
                {
                    ds.PropertiesToLoad.Add(a);
                }


                var result = ds.FindOne();
                if (result != null)
                {
                    p = processResult(result);
                }
            }
            return(p);
        }
コード例 #4
0
        public Contact processResult(SearchResult result)
        {
            Contact p = new Contact();

            if (result.Properties.Contains("name"))
            {
                p.Name = result.Properties["name"][0].ToString();
            }

            if (result.Properties.Contains("displayname"))
            {
                p.DisplayName = result.Properties["displayname"][0].ToString();
            }

            if (result.Properties.Contains("wWWHomePage"))
            {
                p.Url = result.Properties["wWWHomePage"][0].ToString();
            }

            if (result.Properties.Contains("sn"))
            {
                p.SurName = result.Properties["sn"][0].ToString();
            }

            if (result.Properties.Contains("givenname"))
            {
                p.GivenName = result.Properties["givenname"][0].ToString();
            }

            if (result.Properties.Contains("description"))
            {
                p.Description = result.Properties["description"][0].ToString();
            }

            if (result.Properties.Contains("thumbnailPhoto"))
            {
                p.Thumbnail = (byte[])result.Properties["thumbnailPhoto"][0];
            }

            if (result.Properties.Contains("department"))
            {
                p.Department = result.Properties["department"][0].ToString();
            }

            if (result.Properties.Contains("physicalDeliveryOfficeName"))
            {
                p.Office = result.Properties["physicalDeliveryOfficeName"][0].ToString();
            }

            if (result.Properties.Contains("mobile"))
            {
                p.MobileNumber = result.Properties["mobile"][0].ToString();
            }

            if (result.Properties.Contains("title"))
            {
                p.Title = result.Properties["title"][0].ToString();
            }

            if (result.Properties.Contains("mail"))
            {
                p.EMail = result.Properties["mail"][0].ToString().ToLower();
            }

            if (result.Properties.Contains("telephoneNumber"))
            {
                p.TelephoneNumber = result.Properties["telephoneNumber"][0].ToString();
            }

            if (result.Properties.Contains("facsimileTelephoneNumber"))
            {
                p.FaxNumber = result.Properties["facsimileTelephoneNumber"][0].ToString();
            }

            if (result.Properties.Contains("userPrincipalName"))
            {
                p.UserPrincipalName = result.Properties["userPrincipalName"][0].ToString();
            }

            if (result.Properties.Contains("DistinguishedName"))
            {
                p.DistinguishedName = result.Properties["DistinguishedName"][0].ToString();
            }

            if (result.Properties.Contains("manager"))
            {
                LDAPSearchObject search = new LDAPSearchObject();
                search.AND.Add("distinguishedName", result.Properties["manager"][0].ToString());
                p.Manager = findContact(search);
            }

            if (result.Properties.Contains("st"))
            {
                p.State = result.Properties["st"][0].ToString();
            }

            if (result.Properties.Contains("streetAddress"))
            {
                p.Address = result.Properties["streetAddress"][0].ToString();
            }

            if (result.Properties.Contains("postalCode"))
            {
                p.PostalCode = result.Properties["postalCode"][0].ToString();
            }

            if (result.Properties.Contains("l"))
            {
                p.City = result.Properties["l"][0].ToString();
            }

            return(p);
        }