Is this really the version you are looking for? Kentico Xperience 8 Documentation is no longer updated. Use the switcher in the header to choose your product version.
Kentico EMS required
Features described on this page require the Kentico EMS license.
using System;
using System.Data;
using CMS.OnlineMarketing;
using CMS.WebAnalytics;
using CMS.DataEngine;
using CMS.Helpers;
using CMS.SiteProvider;
using CMS.Base;private bool CreateActivity()
{
// Gets a dataset of contacts
string where = "ContactLastName LIKE N'My New Contact%'";
var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(1);
if (!DataHelper.DataSourceIsEmpty(contacts))
{
// Gets the contact from the dataset
ContactInfo contact = contacts.First();
// Gets the activity type
ActivityTypeInfo activityType = ActivityTypeInfoProvider.GetActivityTypes().First();
// Creates a new activity object
ActivityInfo newActivity = new ActivityInfo()
{
ActivityType = activityType.ActivityTypeName,
ActivityTitle = "My new activity",
ActivitySiteID = SiteContext.CurrentSiteID,
ActivityOriginalContactID = contact.ContactID,
ActivityActiveContactID = contact.ContactID
};
// Saves the activity
ActivityInfoProvider.SetActivityInfo(newActivity);
return true;
}
return false;
}private bool GetAndUpdateActivity()
{
// Gets a dataset of contacts
string where = "ContactLastName LIKE N'My New Contact%'";
var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(1);
if (!DataHelper.DataSourceIsEmpty(contacts))
{
// Gets the contact from the dataset
ContactInfo contact = contacts.First<ContactInfo>();
// Gets all activities associated with the contact
var updateActivities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityActiveContactID", contact.ContactID);
if (updateActivities.Any())
{
// Gets the first activity
ActivityInfo activity = updateActivities.First();
// Updates the activity
activity.ActivityTitle = activity.ActivityTitle.ToLowerCSafe();
// Saves the activity
ActivityInfoProvider.SetActivityInfo(activity);
return true;
}
}
return false;
}private bool GetAndBulkUpdateActivities()
{
// Gets a dataset of contacts
string where = "ContactLastName LIKE N'My New Contact%'";
var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(1);
if (!DataHelper.DataSourceIsEmpty(contacts))
{
// Gets the contact from the dataset
ContactInfo contact = contacts.First<ContactInfo>();
// Gets all activities associated with the contact
var updateActivities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityActiveContactID", contact.ContactID);
if (updateActivities.Any())
{
foreach (ActivityInfo activity in updateActivities)
{
// Updates the activity content
activity.ActivityTitle = activity.ActivityTitle.ToUpper();
// Saves the activity
ActivityInfoProvider.SetActivityInfo(activity);
}
return true;
}
}
return false;
}private bool DeleteActivity()
{
// Gets a dataset of contacts
string where = "ContactLastName LIKE N'My New Contact%'";
var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(1);
if (!DataHelper.DataSourceIsEmpty(contacts))
{
// Gets the contact from the dataset
ContactInfo contact = contacts.First<ContactInfo>();
// Gets all activities associated with the contact
var activities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityOriginalContactID", contact.ContactID);
if (activities.Any())
{
foreach (ActivityInfo activity in activities)
{
// Deletes the contact's activities
ActivityInfoProvider.DeleteActivityInfo(activity);
}
return true;
}
}
return false;
}