Beispiel #1
0
        public List <ContactDTO> GetAllContacts(DateTime modifiedOnOrAfter)
        {
            _getMessage?.Invoke("Loading contacts started");
            ContactsController contactController = new ContactsController(_apiKey, _baseURL);

            ListRequestOptions opts = new ListRequestOptions {
                PropertiesToInclude = new List <string> {
                    "firstname", "lastname", "lifecyclestage", "associatedcompanyid"
                }
            };

            opts.Limit      = 100;
            opts.timeOffset = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();

            List <ContactDTO> contactList = new List <ContactDTO>();

            bool hasMore = true;

            while (hasMore)
            {
                ContactListResponse pageContacts = contactController.GetPageContacts(opts);
                ContactMapper.ToContactList(pageContacts, ref contactList, modifiedOnOrAfter, out hasMore);

                _getMessage?.Invoke($"Loaded {contactList.Count} contacts");

                hasMore = hasMore & pageContacts.HasMore;
                if (hasMore)
                {
                    opts.timeOffset = pageContacts.TimeOffset;
                }
            }

            List <CompanyResponse> companyResponseList = GetAllCompanies(contactList);

            ContactMapper.Map(ref contactList, companyResponseList);

            return(contactList);
        }