public async Task <HttpStatusCode> UpdateContactAsync(Contact contact) { contact.LastModifiedTime = UnixTicks(DateTime.Now).ToString(CultureInfo.InvariantCulture); contact.Id = null; var setContact = new AddOrUpdateWrapper <Contact>() { Update = new[] { contact } }; var response = await this._client.PostAsJsonAsync( "v2/json/contacts/set", new { request = new { contacts = setContact } }); return(response.StatusCode); }
public async Task <HttpStatusCode> UpdateVisitorIdForUserLead(string userEmail, string visitorId, string videoFriendlyUrl) { if (!this.PipelinePreStatusesForVideos.ContainsKey(videoFriendlyUrl)) { throw new Exception(); } var preStatusesForCurrent = this.PipelinePreStatusesForVideos[videoFriendlyUrl]; var leadsResponse = await this.GetLeadByEmail(userEmail); if (leadsResponse?.Response?.Leads != null) { var leadsToUpdate = new List <Lead>(); foreach (var lead in leadsResponse.Response.Leads) { var newLastModifiedData = Convert.ToInt64(lead.LastModifiedTime) + 100; if (preStatusesForCurrent.Contains(lead.StatusId)) { lead.VisitorId = visitorId; lead.StatusId = PipelineVideoStatuses[videoFriendlyUrl]; lead.LastModifiedTime = newLastModifiedData.ToString(); leadsToUpdate.Add(lead); } } if (!leadsToUpdate.Any()) { throw new Exception(); } var setModel = new AddOrUpdateWrapper <Lead> { Update = leadsToUpdate.ToArray() }; var response = await this._client.PostAsJsonAsync( "v2/json/leads/set", new { request = new { leads = setModel } }); var updateResult = await response.Content.ReadAsAsync <dynamic>(); return(response.StatusCode); } throw new Exception(); }
public async Task <HttpResponseWrapper <SetLeadsRequest> > AddLeadAsync(string name, string visitorId) { var newLead = new Lead { Name = name, VisitorId = visitorId }; var setModel = new AddOrUpdateWrapper <Lead> { Add = new[] { newLead } }; var setLeadsRequest = new SetLeadsRequest { Leads = setModel }; var request = new HttpRequestWrapper <SetLeadsRequest> { Request = setLeadsRequest }; var response = await this._client.PostAsJsonAsync( "v2/json/leads/set", new { request = new { leads = setModel } }); var d = await response.Content.ReadAsAsync <HttpResponseWrapper <SetLeadsRequest> >(); return(d); }