Contact groups


List of examples:

Creating a contact group




// Creates a new contact group object
ContactGroupInfo newGroup = new ContactGroupInfo()
{
    ContactGroupDisplayName = "New group",
    ContactGroupName = "NewGroup",
    ContactGroupEnabled = true,
    ContactGroupDynamicCondition = "{%Contact.ContactLastName.Contains(\"Smith\")%}"
};

// Saves the contact group to the database
ContactGroupInfo.Provider.Set(newGroup);


> Back to list of examples

Updating a contact group



// Gets the contact group
ContactGroupInfo updateGroup = ContactGroupInfo.Provider.Get("NewGroup");

if (updateGroup != null)
{
    // Updates the contact group's properties
    updateGroup.ContactGroupDisplayName = updateGroup.ContactGroupDisplayName.ToLowerCSafe();

    // Saves the modified contact group to the database
    ContactGroupInfo.Provider.Set(updateGroup);
}

> Back to list of examples

Updating multiple contact groups



// Gets all contact groups whose name starts with 'New'
var groups = ContactGroupInfo.Provider.Get().WhereStartsWith("ContactGroupName", "New");

// Loops through individual contact groups
foreach (ContactGroupInfo group in groups)
{
    // Updates the contact group properties
    group.ContactGroupDisplayName = group.ContactGroupDisplayName.ToUpper();

    // Saves the modified contact group to the database
    ContactGroupInfo.Provider.Set(group);
}

> Back to list of examples

Adding contacts to a contact group



// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets all contacts whose last name is 'Smith'
    var contacts = ContactInfo.Provider.Get().WhereEquals("ContactLastName", "Smith");

    // Loops through individual contacts
    foreach (ContactInfo contact in contacts)
    {
        // Creates an object representing the relationship between the contact and the group
        ContactGroupMemberInfo newContactGroupMember = new ContactGroupMemberInfo()
        {
            ContactGroupMemberContactGroupID = group.ContactGroupID,
            ContactGroupMemberType = ContactGroupMemberTypeEnum.Contact,
            ContactGroupMemberRelatedID = contact.ContactID,
            ContactGroupMemberFromManual = true
        };

        // Saves the contact-group relationship to the database
        ContactGroupMemberInfo.Provider.Set(newContactGroupMember);
    }
}

> Back to list of examples

Removing contacts from a contact group



// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first contact whose last name is 'Smith'
    ContactInfo contact = ContactInfo.Provider.Get()
                                        .WhereEquals("ContactLastName", "Smith")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Gets the relationship between the contact and the contact group
    ContactGroupMemberInfo contactGroupMember =
        ContactGroupMemberInfo.Provider.Get(group.ContactGroupID, contact.ContactID, ContactGroupMemberTypeEnum.Contact);

    if (contactGroupMember != null)
    {
        // Removes the contact from the contact group
        ContactGroupMemberInfo.Provider.Delete(contactGroupMember);
    }
}

> Back to list of examples

Adding accounts to a contact group



// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first the account whose name starts with 'New"
    AccountInfo account = AccountInfo.Provider.Get()
                                        .WhereStartsWith("AccountName", "New")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Creates an object representing the relationship between the account and the contact group
    ContactGroupMemberInfo newContactGroupAccountMember = new ContactGroupMemberInfo()
    {
        ContactGroupMemberContactGroupID = group.ContactGroupID,
        ContactGroupMemberType = ContactGroupMemberTypeEnum.Account,
        ContactGroupMemberRelatedID = account.AccountID
    };

    // Saves the account-contact group relationship to the database
    ContactGroupMemberInfo.Provider.Set(newContactGroupAccountMember);
}

> Back to list of examples

Removing accounts from a contact group



// Gets the contact group
ContactGroupInfo group = ContactGroupInfo.Provider.Get("NewGroup");

if (group != null)
{
    // Gets the first the account whose name starts with 'New"
    AccountInfo account = AccountInfo.Provider.Get()
                                        .WhereStartsWith("AccountName", "New")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Gets the relationship between the account and the contact group
    ContactGroupMemberInfo contactGroupAccountMember =
        ContactGroupMemberInfo.Provider.Get(group.ContactGroupID, account.AccountID, ContactGroupMemberTypeEnum.Account);

    if (contactGroupAccountMember != null)
    {
        // Removes the account from the contact group
        ContactGroupMemberInfo.Provider.Delete(contactGroupAccountMember);
    }
}

> Back to list of examples

Deleting a contact group



// Gets the contact group
ContactGroupInfo deleteGroup = ContactGroupInfo.Provider.Get("NewGroup");

if (deleteGroup != null)
{
    // Deletes the contact group
    ContactGroupInfo.Provider.Delete(deleteGroup);
}

> Back to list of examples