Contact groups
List of examples:
- Creating a contact group
- Updating a contact group
- Updating multiple contact groups
- Adding contacts to a contact group
- Removing contacts from a contact group
- Adding accounts to a contact group
- Removing accounts from a contact group
- Deleting a contact group
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
ContactGroupInfoProvider.SetContactGroupInfo(newGroup);
Updating a contact group
// Gets the contact group
ContactGroupInfo updateGroup = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (updateGroup != null)
{
// Updates the contact group's properties
updateGroup.ContactGroupDisplayName = updateGroup.ContactGroupDisplayName.ToLowerCSafe();
// Saves the modified contact group to the database
ContactGroupInfoProvider.SetContactGroupInfo(updateGroup);
}
Updating multiple contact groups
// Gets all contact groups whose name starts with 'New'
var groups = ContactGroupInfoProvider.GetContactGroups().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
ContactGroupInfoProvider.SetContactGroupInfo(group);
}
Adding contacts to a contact group
// Gets the contact group
ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (group != null)
{
// Gets all contacts whose last name is 'Smith'
var contacts = ContactInfoProvider.GetContacts().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
ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(newContactGroupMember);
}
}
Removing contacts from a contact group
// Gets the contact group
ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (group != null)
{
// Gets the first contact whose last name is 'Smith'
ContactInfo contact = ContactInfoProvider.GetContacts()
.WhereEquals("ContactLastName", "Smith")
.TopN(1)
.FirstOrDefault();
// Gets the relationship between the contact and the contact group
ContactGroupMemberInfo contactGroupMember =
ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(group.ContactGroupID, contact.ContactID, ContactGroupMemberTypeEnum.Contact);
if (contactGroupMember != null)
{
// Removes the contact from the contact group
ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(contactGroupMember);
}
}
Adding accounts to a contact group
// Gets the contact group
ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (group != null)
{
// Gets the first the account whose name starts with 'New"
AccountInfo account = AccountInfoProvider.GetAccounts()
.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
ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(newContactGroupAccountMember);
}
Removing accounts from a contact group
// Gets the contact group
ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (group != null)
{
// Gets the first the account whose name starts with 'New"
AccountInfo account = AccountInfoProvider.GetAccounts()
.WhereStartsWith("AccountName", "New")
.TopN(1)
.FirstOrDefault();
// Gets the relationship between the account and the contact group
ContactGroupMemberInfo contactGroupAccountMember =
ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(group.ContactGroupID, account.AccountID, ContactGroupMemberTypeEnum.Account);
if (contactGroupAccountMember != null)
{
// Removes the account from the contact group
ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(contactGroupAccountMember);
}
}
Deleting a contact group
// Gets the contact group
ContactGroupInfo deleteGroup = ContactGroupInfoProvider.GetContactGroupInfo("NewGroup");
if (deleteGroup != null)
{
// Deletes the contact group
ContactGroupInfoProvider.DeleteContactGroupInfo(deleteGroup);
}