public static AYUTSUser Get(string userId) { var customer = new AYUTSUser(); var entry = new DirectoryEntry("LDAP://doh.ad.state.fl.us"); var search = new DirectorySearcher(entry); search.Filter = string.Format("(&(objectClass=user)(samAccountName={0}))", userId); search.PropertiesToLoad.Add("samAccountName"); search.PropertiesToLoad.Add("mail"); search.PropertiesToLoad.Add("givenName"); search.PropertiesToLoad.Add("sn"); search.PropertiesToLoad.Add("telephoneNumber"); search.PropertiesToLoad.Add("physicalDeliveryOfficeName"); search.PropertiesToLoad.Add("department"); search.PropertiesToLoad.Add("streetAddress"); search.PropertiesToLoad.Add("l"); search.PropertiesToLoad.Add("co"); search.PropertiesToLoad.Add("postalCode"); try { var user = search.FindOne(); customer.UserID = user.Properties["samAccountName"][0].ToString(); customer.EmailAddress = user.Properties["mail"][0].ToString(); customer.FirstName = user.Properties["givenName"][0].ToString(); customer.LastName = user.Properties["sn"][0].ToString(); try { customer.Phone = user.Properties["telephoneNumber"][0].ToString(); } catch { customer.Phone = "NOT PROVIDED"; } try { customer.Office = user.Properties["physicalDeliveryOfficeName"][0].ToString(); } catch { customer.Office = "NOT PROVIDED"; } try { customer.Department = user.Properties["department"][0].ToString(); } catch { customer.Department = "NOT PROVIDED"; } try { customer.StreetAddress = user.Properties["streetAddress"][0].ToString(); } catch { customer.StreetAddress = "NOT PROVIDED"; } try { customer.City = user.Properties["l"][0].ToString(); } catch { customer.City = "NOT PROVIDED"; } try { customer.County = user.Properties["co"][0].ToString(); } catch { customer.County = "NOT PROVIDED"; } try { customer.ZipCode = user.Properties["postalCode"][0].ToString(); } catch { customer.ZipCode = "NOT PROVIDED"; } } catch (Exception e) { throw e; } return customer; }
public static AYUTSUser GetTest() { var user = new AYUTSUser(); user.UserID = "MartinCX"; user.City = "Tallahassee"; user.County = "LEON"; user.Department = "Office of Information Technology"; user.EmailAddress = "*****@*****.**"; user.FirstName = "Chris"; user.LastName = "Martin"; user.Office = "ESPS"; user.Phone = "555-555-5555 x 555"; user.StreetAddress = "Place"; user.ZipCode = "32305"; return user; }