private static void UpdateTelephoneContact(Employee employee, eTelephoneContactType contactDetailType, SearchResult searchResult, string field, string displayName) { if (searchResult.Properties[field].Count > 0) { TelephoneContact officeContact = (TelephoneContact) employee.ContactCard.FirstOrDefault( tc => tc.ContactDetailType == eContactDetailType.ContactNumber && tc.DisplayName.Equals(displayName)); if (officeContact == null) { officeContact = new TelephoneContact() { DisplayName = displayName, TelephoneType = contactDetailType }; employee.ContactCard.Add(officeContact); } officeContact.SetNumber(searchResult.Properties[field][0].ToString()); } }
private static void importDirectecty() { string path = "c:\\temp\\ed.csv"; TextFieldParser parser = new TextFieldParser(path); parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); string[] header; while (!parser.EndOfData) { //Process row string[] fields = parser.ReadFields(); if (parser.LineNumber == 2) { // Header header = fields; continue; } Employee e = new Employee(); e.BaseLocation = fields[0]; e.Active = true; e.FullName = fields[1]; e.SecurityIdentifier = fields[2].Split('@')[0] + "_sym"; e.Title = ""; e.ContactCard.Add(new EmailContact() {DisplayName = "Work Email", EmailAddress = fields[2], Primary = true}); if (!string.IsNullOrEmpty(fields[3])) { e.ContactCard.Add(new TelephoneContact() { TelephoneType = eTelephoneContactType.Office, Primary = e.BaseLocation == "LDN", CountryCode = "44", DisplayName = "London Office", AreaCode = "(0)207", Number = "072", Extension = fields[3].Split(' ')[3] }); } if (!string.IsNullOrEmpty(fields[4])) { e.ContactCard.Add(new TelephoneContact() { TelephoneType = eTelephoneContactType.Office, Primary = e.BaseLocation == "HK", CountryCode = "852", DisplayName = "HK Office", Number = "369", Extension = fields[4].Split(' ')[2] }); } if (!string.IsNullOrEmpty(fields[5])) { e.ContactCard.Add(new TelephoneContact() { TelephoneType = eTelephoneContactType.Mobile, CountryCode = "44", DisplayName = "London Mobile", Number = fields[5].Split(' ')[1] + fields[5].Split(' ')[2] + fields[5].Split(' ')[3] }); } if (!string.IsNullOrEmpty(fields[6])) { e.ContactCard.Add(new TelephoneContact() { TelephoneType = eTelephoneContactType.Mobile, CountryCode = "852", DisplayName = "HK Mobile", Number = fields[6].Split(' ')[1] + fields[6].Split(' ')[2] }); } e.Save(); } parser.Close(); }