Kentico CMS 6.0 On-line Marketing Guide

Managing contact roles

Managing contact roles

Previous topic Next topic Mail us feedback on this topic!  

Managing contact roles

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

The following example creates a contact role.

 

private bool CreateContactRole()

{

  // Create new contact role object

  ContactRoleInfo newRole = new ContactRoleInfo()

       {

           ContactRoleDisplayName = "My new role",

           ContactRoleName = "MyNewRole",

           ContactRoleSiteID = CMSContext.CurrentSiteID

       };

 

  // Save the contact role

  ContactRoleInfoProvider.SetContactRoleInfo(newRole);

 

  return true;

}

 

The following example gets and updates the contact role created by the example above.

 

private bool GetAndUpdateContactRole()

{

  // Get the contact role

  ContactRoleInfo updateRole = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName);

  if (updateRole != null)

   {

      // Update a property

       updateRole.ContactRoleDisplayName = updateRole.ContactRoleDisplayName.ToLower();

 

      // Save the changes

      ContactRoleInfoProvider.SetContactRoleInfo(updateRole);

 

      return true;

   }

 

  return false;

}

 

The following example gets and bulk updates multiple contact roles specified by a WHERE condition.

 

private bool GetAndBulkUpdateContactRoles()

{

  // Get the contact roles dataset

  string where = "ContactRoleName LIKE N'MyNewRole%'";

  InfoDataSet<ContactRoleInfo> roles = ContactRoleInfoProvider.GetContactRoles(where, null);

 

  if (!DataHelper.DataSourceIsEmpty(roles))

   {

      foreach (ContactRoleInfo role in roles)

       {

          // Update the properties

           role.ContactRoleDisplayName = role.ContactRoleDisplayName.ToUpper();

 

          // Save the changes

          ContactRoleInfoProvider.SetContactRoleInfo(role);

       }

 

      return true;

   }

 

  return false;

}

 

The following example deletes the contact role created by the first example in this topic.

 

private bool DeleteContactRole()

{

  // Get the contact role

  ContactRoleInfo deleteRole = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName);

 

  if (deleteRole != null)

   {

      // Delete the contact role

      ContactRoleInfoProvider.DeleteContactRoleInfo(deleteRole);

 

      return true;

   }

 

  return false;

}