public static object[] search(string phoneNumber) { List<ABPerson> singlePeople = new List<ABPerson> (); phoneNumber = Regex.Replace (phoneNumber, "[^0-9]", ""); ABAddressBook ab = new ABAddressBook (); var people = ab.Where (x => x is ABPerson).Cast<ABPerson> ().Where (x => x.GetPhones ().Where (p => Regex.Replace (p.Value, "[^0-9]", "").Contains (phoneNumber) || phoneNumber.Contains (Regex.Replace (p.Value, "[^0-9]", ""))).Count () > 0).ToArray (); foreach (var person in people) { if (singlePeople.Intersect (person.GetRelatedNames ().Cast<ABPerson> ()).Count () <= 0) singlePeople.Add (person); } return singlePeople.ToArray (); }
public static List <ABPerson> GetPersonsFromGroup(string groupName) { List <ABPerson> result = new List <ABPerson>(); foreach (var g in connection.GetPersonsFromGroup(groupName)) { ABPerson p = null; IEnumerable <ABRecord> record = AddressBook.Where(x => x.Id == g.ABPersonId); if (record != null) { p = record.FirstOrDefault() as ABPerson; } // ABPerson is unfindable! remove it from database! if (p == null) { int removedId = connection.RemoveGroupPerson(g); } result.Add(p); } return(result); }
public static object[] search(string phoneNumber) { List <ABPerson> singlePeople = new List <ABPerson> (); phoneNumber = Regex.Replace(phoneNumber, "[^0-9]", ""); ABAddressBook ab = new ABAddressBook(); var people = ab.Where(x => x is ABPerson).Cast <ABPerson> ().Where(x => x.GetPhones().Where(p => Regex.Replace(p.Value, "[^0-9]", "").Contains(phoneNumber) || phoneNumber.Contains(Regex.Replace(p.Value, "[^0-9]", ""))).Count() > 0).ToArray(); foreach (var person in people) { if (singlePeople.Intersect(person.GetRelatedNames().Cast <ABPerson> ()).Count() <= 0) { singlePeople.Add(person); } } return(singlePeople.ToArray()); }