BusinessComponents.OperationsComponent.GetContacts C# (CSharp) Метод

GetContacts() публичный статический Метод

Get the contacts for a given list along with some contact details
public static GetContacts ( CredentialsDetails credentialsDetail, string listId, string &strRequest, string &strResponse ) : List
credentialsDetail BusinessObjects.CredentialsDetails An object that encapsulates the Constant Contact credentials
listId string The id of the list for witch the contacts will be brought
strRequest string The request string representation
strResponse string The response string representation
Результат List
        public static List<ContactDetails> GetContacts(CredentialsDetails credentialsDetail, string listId,
            out string strRequest, out string strResponse)
        {
            var contactCollection = new List<ContactDetails>();

            var xmlResponse = ApiCallComponent.CallServiceGet(credentialsDetail, listId + "/members", out strRequest,
                                                              out strResponse);

            var xdoc = XDocument.Parse(xmlResponse);

            if (xdoc.Root == null)
            {
                return null;
            }

            var contacts = from f in xdoc.Root.Descendants(W3Ns + "entry")
                           let element = f.Element(W3Ns + "id")
                           where element != null
                           select new
                                      {
                                          id = "https" + Regex.Split(element.Value, "http")[1]
                                      };

            foreach (var contact in contacts)
            {
                string req;
                string res;

                var xmlContact = ApiCallComponent.CallServiceGet(credentialsDetail, contact.id, out req, out res);

                var contactDetails = new ContactDetails();

                var xContact = XDocument.Parse(xmlContact);

                var c = (from f in xContact.Descendants(W3Ns + "content")
                         let element = f.Element(ConstantContactNs + "Contact")
                         where element != null
                         let element0 = element.Element(ConstantContactNs + "EmailAddress")
                         where element0 != null
                         let element1 = element.Element(ConstantContactNs + "FirstName")
                         where element1 != null
                         let element2 = element.Element(ConstantContactNs + "LastName")
                         where element2 != null
                         let element3 = element.Element(ConstantContactNs + "InsertTime")
                         where element3 != null
                         select new
                                    {
                                        email = element0.Value,
                                        firstName = element1.Value,
                                        lastName = element2.Value,
                                        updated = element3.Value
                                    }).ToList();

                var firstOrDefault = c.FirstOrDefault();
                if (firstOrDefault != null)
                {
                    contactDetails.Id = contact.id;
                    contactDetails.FirstName = firstOrDefault.firstName;
                    contactDetails.LastName = firstOrDefault.lastName;
                    contactDetails.CreateDate = string.Format("{0:MMM d, yyyy}", DateTime.Parse(firstOrDefault.updated));
                    contactDetails.Email = firstOrDefault.email;
                }

                contactCollection.Add(contactDetails);
            }

            return contactCollection;
        }