Sitefinity CMS

Events API Overview Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content Based Modules > Events > Events API Overview

Glossary Item Box

The Events module allows users to easily create and manage events. The Events module provides the Events View and Events Scheduler public controls for displaying events. This topic provides information of how to use the EventsManager class.

 

The Events module is based on Generic Content. Most methods used by EventsManager are actually methods of the ContentManager class. 

For more information on the ContentManager class, see Generic Content API Overview of Generic Content API.

 

The Content property of the EventsManager class is the instance of ContentManager instantiated with a proper provider for Events. While all Generic Content based modules (such as Blogs, Events, News, and so on) are using the ContentManager class for most of their data-related work, it is necessary that ContentManager is instantiated through the respective module's Content property, and not directly through ContentManager's constructor.

 

How to Start Using the EventsManager Class

You can create a new instance of the EventsManager class anywhere in your code in order to work with Events module data. If working in an assembly, make sure you reference the Telerik.Events assembly before you use the EventsManager class.


In order to start using Events module API, create a new instance of the EventsManager class: 

Create a new instance of EventsManager with specified provider name:

Copy Code
// creates new instance of EventsManager class with provider name as parameter,
// which means that EventsManager will use specified provider when working with data
Telerik.Events.EventsManager eventsManager = new Telerik.Events.EventsManager("MyCustomProvider");

 

Working with Events

Since the Events module is based on the Generic Content module, a large number of methods used for manipulating Events are performed by ContentManager (initialized with a proper Events provider). Every event is actually an object of IContent type. So, in order to allow access to content manipulation methods , EventsManager exposes the public property Content of type ContentManager. This allows developers to use common methods for retrieving, creating, updating and deleting content as well as comments, categories and tags.

 

In some scenarios events could be treated exclusively as content items (IContent objects). However, for other events the most important aspects are their start and end dates. In such cases, the two EventsManager properties are the most suitable to use: EventStart and EventEnd. They are stored as meta fields. The EventsModule class maintains a lookup table of Events where these are stored in the designated DateTime fields. This results in much better performance when querying Events based on these properties.

 

Choosing between ContentManager Methods and EventsManager Methods

The Events module works with objects of type IEvent. However, since the Events module is based on Generic Content, an event can also be perceived as an IContent object. When working with EventsManager methods, objects will be of type IEvent. On the other hand, if working with ContentManager methods, objects will be of type IContent type.

 

Choosing a manager depends on the particular scenario. For retrieving events based on particular filter (just those where Contact name is John Smith, for example), use the ContentManager class - it provides numerous methods for working with content. On the other hand, for retrieving all events that start this month, use the EventsManager class - it provides more suitable methods.

 

The reason for using EventsManager-specific methods, and IEvent objects, is because objects of types ContentManager and IContent are not well suited for manipulating date-specific content. Still, when content is more important than dates for an event, ContentManager and IContent types of objects provide solid support for working with Events.

 

 

Here are a few examples:

 

• Retrieve events to be displayed in a grid, paging is turned on and particular filter is applied

Use : EventsManager.Content.GetContent(int from, int max, params IMetaSearchInfo[] filter)


• Retrieve events that start in February of this year

Use : EventsManager.GetEvents(DateTime from, DateTime to, string sortExpression)


• Get all comments for a particular IContent object

Use : EventsManager.Content.GetComments(Guid itemId) and pass it the value of IContent.ID property


• Get all comments for a particular IEvent object

Use : EventsManager.Content.GetComments(Guid itemId) and pass it the value of IEvent.ContentID property or IEvent.ContentItem.ID property

 

As the examples demonstrate, every IEvent object carries a reference to the IContent object describing that event. Apart from that, an IEvent object also has properties such as Start and End -this allows much simpler work when dates that signify when an event starts and ends are crucial for the given scenario.


See Also