public IEnumerable <ContactList> GetAllContactLists() { using (var client = new HttpClient()) { var offset = 0; var count = 250; var hasMore = false; do { var contactListRaw = client.GetStringAsync($"https://api.hubapi.com/contacts/v1/lists?count={count}&hapikey={HapiKey}&offset={offset}").Result; ContactListResponse response = JsonConvert.DeserializeObject <ContactListResponse>(contactListRaw); offset = response.offset; hasMore = response.hasmore; foreach (var c in response.lists) { yield return(c); //Console.WriteLine($"name: {c.name}"); } if (hasMore) { Thread.Sleep(1000); } } while (hasMore); } }
public static void ToContactList(ContactListResponse contactListResponse, ref List <ContactDTO> contactList, DateTime modifiedOnOrAfter, out bool hasMore) { hasMore = true; if (contactList == null) { contactList = new List <ContactDTO>(); } foreach (var contactResponse in contactListResponse.Contacts) { long modifiedOnOrAfterUnix = new DateTimeOffset(modifiedOnOrAfter).ToUnixTimeMilliseconds(); long lastmodifieddate = 0; if (long.TryParse(contactResponse.Properties.Lastmodifieddate.Value, out lastmodifieddate)) { if (lastmodifieddate >= modifiedOnOrAfterUnix) { contactList.Add(new ContactDTO { Id = contactResponse.Vid, Firstname = contactResponse.Properties.Firstname?.Value, Lastname = contactResponse.Properties.Lastname?.Value, LifeCycleStage = contactResponse.Properties.Lifecyclestage?.Value, Company_Id = contactResponse.Properties.Associatedcompanyid?.Value }); } else { hasMore = false; return; } } } }
public async Task <ContactListResponse> NoRespondedContacts(int userID, int questionaireID) { var ContactList = Configuration["url"]; ContactListResponse response = await _httlClient.PostJsonAsync <ContactListResponse>(ContactList + "api/Contact/ContactListNoResponded", new ContactListNoRespondedRequest(userID, questionaireID)); return(response); }
public ContactListResponse GetContactList() { var resp = new ContactListResponse(); resp.Contacts = new Contacts(); using (var uow = new ChitFundDbContext(dbConnection)) { var customers = uow.Contacts.GetAllContacts(); foreach (var c in customers) { c.PrimaryType = 1; resp.Contacts.Add(c); } } return(resp); //mocq data //var resp = new CustomerListResponse(); //resp.Customers = new Customers(); //for (int i = 0; i < 5; i++) //{ // Customer c1 = new Customer(); // c1.CustomerId = i; // c1.Name = "mahesh"; // c1.Email = "*****@*****.**"; // c1.Phone = "3432324"; // c1.PrimaryType = 1; // resp.Customers.Add(c1); //} //return resp; }
public ContactListResponse GetPageContacts(ListRequestOptions opts) { if (opts == null) { opts = new ListRequestOptions(); } var fullUrl = $"{ BaseURL }/contacts/v1/lists/recently_updated/contacts/recent?" .SetQueryParam("hapikey", ApiKey); fullUrl.SetQueryParam("count", opts.Limit); if (opts.PropertiesToInclude.Any()) { fullUrl.SetQueryParam("property", opts.PropertiesToInclude); } if (opts.timeOffset.HasValue) { fullUrl = fullUrl.SetQueryParam("timeOffset", opts.timeOffset); } string response = RequestController.GetResponse(fullUrl); //deserialise this to a list of contacts var contactList = ContactListResponse.FromJson(response); return(contactList); }
public async Task <ActionResult> List([FromQuery] ContactListRequest rq) { try { ContactListResponse rs = await(new ContactListService(this.Context, _contactRepo)).RunAsync(rq); return(new ApiActionResult(this.Context.Request, rs)); } catch (Exception ex) { return(new ApiActionResult(this.Context.Request, ex)); } }
public ContactListResponse GetContactList() { var resp = new ContactListResponse(); resp.Contacts = new Models.Contacts(); IContactBS bs = DIFactoryDesigntime.GetInstance<IContactBS>(); IList<Entities.Contact> rtnList = bs.GetContacts(); IBaseConverter<Entities.Contact, Models.Contact> convtResult = new AutoMapConverter<Entities.Contact, Models.Contact>(); var convtList = convtResult.ConvertObjectCollection(rtnList); resp.Contacts.AddRange(convtList); return resp; }
public ContactListResponse GetContactList() { var resp = new ContactListResponse(); resp.Contacts = new Models.Contacts(); IContactBS bs = DIFactoryDesigntime.GetInstance <IContactBS>(); IList <Entities.Contact> rtnList = bs.GetContacts(); IBaseConverter <Entities.Contact, Models.Contact> convtResult = new AutoMapConverter <Entities.Contact, Models.Contact>(); var convtList = convtResult.ConvertObjectCollection(rtnList); resp.Contacts.AddRange(convtList); return(resp); }
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); }