1

我正在尝试使用 c# 包装器将联系人添加到列表中。我的问题是,如果我是第一次添加联系人,我可以成功添加到列表中。但是,如果我通过 Constant Contact Interface 删除联系人并尝试从我的 asp.net C# 函数再次添加联系人,它会失败。

我做了一些研究,我确实明白:1)我首先需要检查联系人电子邮件地址是否存在 2)然后,相应地更新或发布。

对上述任何帮助/建议表示赞赏。我花了很多时间试图完成这项工作,但没有运气。

代码

protected void Page_Load(object sender, EventArgs e)
    {
        ConstantContactBO.Contact c = new ConstantContactBO.Contact();

        AuthenticationData authdata = new AuthenticationData();
        authdata.Username = "";
        authdata.Password = "";
        authdata.ApiKey = "";

        c.EmailAddress = "joe@a.com";

        ContactOptInList theList = new ContactOptInList();
        c.OptInSource = ContactOptSource.ActionByContact;
        theList.ContactList = new ContactList("39");
        c.ContactLists.Add(theList);

        ConstantContactUtility.Utility.CreateNewContact(authdata, c);

}

我希望能够检查电子邮件是否存在,然后更新或将联系人添加到列表中。

4

2 回答 2

1

在这里https://github.com/constantcontact/Constant-Contact-Dot-Net-ASP-Contact-Forms/blob/master/Web/UploadContactForm/AddContactSmallForm.aspx.cs你可以找到你正在寻找的代码的美丽示例, 我相信。如果您正确使用了已识别的产品,您可以在此处找到更多文档http://developer.constantcontact.com/ 。

    string nextChunkId;
    IList<Contact> list = Utility.SearchContactByEmail(AuthenticationData, emailAddress, out nextChunkId);
    if (list.Count == 0)
    {
        // create new Contact
        Contact contact = GetContactInformation();

        Utility.CreateNewContact(AuthenticationData, contact);
        Response.Redirect("~/AddContactConfirmation.aspx");
    }
    else
    {
        throw new ConstantException(String.Format(CultureInfo.CurrentCulture,
            "Email address \"{0}\" is already a contact", txtEmail.Text.Trim()));
    }
于 2012-11-08T23:31:02.373 回答
0

尝试使用 Lambda 表达式

int count = c.ContactLists.Count(cc => cc.EmailAddress == "joe@a.com");
if(count == 0) //does not exist
{
   //add this contact
}
else
{

}
于 2012-11-08T23:17:25.023 回答