protected void btnAddLead_Click(object sender, EventArgs e) { LeadData lead = new LeadData(); lead.BusinessName = txtBusinessName.Text; lead.ComplianceAgent = txtComplianceAgent.Text; lead.ContactName = txtContactName.Text; lead.DOTNo = txtDoT.Text; lead.Email = txtEmail.Text; lead.Notes = txtNotes.Text; lead.PhoneNoForContact = txtBestPhone.Text; lead.SalesPersonID = Convert.ToInt32(Request.Cookies["UserID"].Value); lead.ServiceDiscussed = txtServiceDiscussed.Text; lead.TimeLine = txtTimeLine.Text; bool isLeadAdded = leadHelper.AddLead(lead); IUserServiceContext userServiceContext = new UserServiceContext(_accessToken, _apiKey); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); //List<string> lists = new List<string>() { "1236366064" }; List <string> lists = new List <string>(); string[] emailid = hdnEmailID.Value.Split(','); foreach (string item in emailid) { if (!String.IsNullOrEmpty(item)) { lists.Add(item); } } List <ContactList> contactLists = new List <ContactList>(); foreach (string list in lists) { ContactList contactList = new ContactList() { Id = list }; contactLists.Add(contactList); } if (isLeadAdded) { int leadID = Convert.ToInt32(Request.QueryString["LeadID"]); DailyLeadEntity dailyLead = dailyLeadHelper.GetLeadRecordsByLeadID(leadID); var contactService = serviceFactory.CreateContactService(); string physicalCity = ""; try { physicalCity = dailyLead.PhysicalAddress.Split(',')[1].Split(null)[1]; } catch { } Address address = new Address(); try { address = new Address() { AddressType = "BUSINESS", City = toString(physicalCity), CountryCode = "US", Line1 = toString(dailyLead.MailingAddress.Substring(0, 40)), Line2 = toString(dailyLead.MailingAddress.Substring(0, 40)), PostalCode = toString(dailyLead.ZipCode), StateCode = toString("ID"), }; } catch { address = new Address() { AddressType = "BUSINESS" }; } try { if (dailyLead != null) { Contact contact = new Contact() { Addresses = new List <Address> { address }, Lists = contactLists, CellPhone = dailyLead.PhoneNo, CompanyName = toString(dailyLead.LegalName), Confirmed = true, EmailAddresses = new List <EmailAddress> { new EmailAddress(toString(txtEmail.Text)) }, Fax = dailyLead.PhoneNo, FirstName = txtContactName.Text, HomePhone = txtBestPhone.Text, JobTitle = "Purcell Compliance Lead", LastName = toString(""), PrefixName = "Mr.", WorkPhone = dailyLead.PhoneNo }; contactService.AddContact(contact, false); } else { Contact contact = new Contact() { Addresses = new List <Address> { address }, Lists = contactLists, CellPhone = txtBestPhone.Text, CompanyName = toString(txtBusinessName.Text), Confirmed = true, EmailAddresses = new List <EmailAddress> { new EmailAddress(toString(txtEmail.Text)) }, Fax = txtBestPhone.Text, FirstName = txtContactName.Text, HomePhone = txtBestPhone.Text, JobTitle = "Purcell Compliance Lead", LastName = toString(""), PrefixName = "Mr.", WorkPhone = txtBestPhone.Text }; contactService.AddContact(contact, false); } Response.Write("<script>alert('Lead added Successfully.');</script>"); resetControls(); } catch { //Response.Write("<script>alert('" + ex.Message + "');</script>"); } } else { Response.Write("<script>alert('Some error occured.');</script>"); } }
private void btnSave_Click(object sender, EventArgs e) { btnSave.Enabled = false; string messageResult = string.Empty; if (string.IsNullOrWhiteSpace(txtEmail.Text)) { MessageBox.Show("Please provide an email address!", "Warning"); } else { try { //get contact if exists (by email address) Contact contact = null; try { contact = GetContactByEmailAddress(txtEmail.Text.Trim()); } catch (CtctException ctcEx) { //contact not found } bool alreadyExists = contact != null ? true : false; contact = UpdateContactFields(contact); Contact result = null; var contactService = _constantContactFactory.CreateContactService(); if (alreadyExists) { result = contactService.UpdateContact(contact, false); } else { result = contactService.AddContact(contact, false); } if (result != null) { if (alreadyExists) { messageResult = "Changes successfully saved!"; } else { messageResult = "Contact successfully added!"; } } else { if (alreadyExists) { messageResult = "Failed to save changes!"; } else { messageResult = "Failed to add contact!"; } } MessageBox.Show(messageResult, "Result"); } catch (IllegalArgumentException illegalEx) { MessageBox.Show(GetExceptionsDetails(illegalEx, "IllegalArgumentException"), "Exception"); } catch (CtctException ctcEx) { MessageBox.Show(GetExceptionsDetails(ctcEx, "CtctException"), "Exception"); } catch (OAuth2Exception oauthEx) { MessageBox.Show(GetExceptionsDetails(oauthEx, "OAuth2Exception"), "Exception"); } catch (Exception ex) { MessageBox.Show(GetExceptionsDetails(ex, "Exception"), "Exception"); } } btnSave.Enabled = true; }