Kentico CMS 7.0 On-line Marketing Guide

Managing activities

Managing activities

Previous topic Next topic Mail us feedback on this topic!  

Managing activities

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

The following example logs an activity.

 

private bool CreateActivity()

{

  // Get dataset of contacts

  string where = "ContactLastName LIKE N'My New Contact%'";

  InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);

 

  if (!DataHelper.DataSourceIsEmpty(contacts))

   {

      // Get the contact from dataset

      ContactInfo contact = contacts.First<ContactInfo>();

 

      // Get an activity type

      ActivityTypeInfo activityType = ActivityTypeInfoProvider.GetActivityTypes(null, null, 1, null).First<ActivityTypeInfo>();

 

      // Create new activity object

      ActivityInfo newActivity = new ActivityInfo()

           {

               ActivityType = activityType.ActivityTypeName,

               ActivityTitle = "My new activity",

               ActivitySiteID = CMSContext.CurrentSiteID,

               ActivityOriginalContactID = contact.ContactID,

               ActivityActiveContactID = contact.ContactID

           };

 

      // Save the activity

      ActivityInfoProvider.SetActivityInfo(newActivity);

 

      return true;

   }

 

  return false;

}

 

The following example gets and updates a the activity logged by the example above.

 

private bool GetAndUpdateActivity()

{

  // Get dataset of contacts

  string where = "ContactLastName LIKE N'My New Contact%'";

  InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);

 

  if (!DataHelper.DataSourceIsEmpty(contacts))

   {

      // Get the contact from dataset

      ContactInfo contact = contacts.First<ContactInfo>();

 

      // Get all activities associated with user

       where = String.Format("ActivityActiveContactID = '{0}'", contact.ContactID);

      InfoDataSet<ActivityInfo> updateActivities = ActivityInfoProvider.GetActivities(where, null);

 

      if (!DataHelper.DataSourceIsEmpty(updateActivities))

       {

          // Get just the first activity

          ActivityInfo activity = updateActivities.First<ActivityInfo>();

 

          // Update the activity

           activity.ActivityTitle = activity.ActivityTitle.ToLower();

 

          // Save the activity

          ActivityInfoProvider.SetActivityInfo(activity);

 

          return true;

       }

   }

 

  return false;

}

 

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

 

private bool GetAndBulkUpdateActivities()

{

  // Get dataset of contacts

  string where = "ContactLastName LIKE N'My New Contact%'";

  InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);

 

  if (!DataHelper.DataSourceIsEmpty(contacts))

   {

      // Get the contact from dataset

      ContactInfo contact = contacts.First<ContactInfo>();

 

      // Get all activities associated with contact

       where = String.Format("ActivityActiveContactID = '{0}'", contact.ContactID);

      InfoDataSet<ActivityInfo> updateActivities = ActivityInfoProvider.GetActivities(where, null);

 

      if (!DataHelper.DataSourceIsEmpty(updateActivities))

       {

 

          foreach (ActivityInfo activity in updateActivities)

           {

              // Update activity content

               activity.ActivityTitle = activity.ActivityTitle.ToLower();

 

              // Save the activity

              ActivityInfoProvider.SetActivityInfo(activity);

           }

 

          return true;

       }

   }

 

  return false;

}

 

The following example deletes the activity logged by the first example in this topic.

 

private bool DeleteActivity()

{

  // Get dataset of contacts

  string where = "ContactLastName LIKE N'My New Contact%'";

  InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);

 

  if (!DataHelper.DataSourceIsEmpty(contacts))

   {

      // Get the contact from dataset

      ContactInfo contact = contacts.First<ContactInfo>();

 

      // Get all activities associated with contact

       where = String.Format("ActivityOriginalContactID = '{0}'", contact.ContactID);

      InfoDataSet<ActivityInfo> activities = ActivityInfoProvider.GetActivities(where, null);

 

      if (!DataHelper.DataSourceIsEmpty(activities))

       {

          foreach (ActivityInfo activity in activities)

           {

              // Delete the object

              ActivityInfoProvider.DeleteActivityInfo(activity);

           }

 

          return true;

       }

   }

 

  return false;

}