IDataEvent

The IDataEventrepresents a contract for event notification containing minimal information about modified items. As you want to have a global event for all content, you can subscribe to the IDataEvent - it will be thrown on the Create, Update, and Delete actions for all content. Inside the event handler you can get information about the:

  • Event Action
    • New (corresponds to Create action)
    • Updated
    • Deleted
  • ItemType
  • ItemId
  • ProviderName

This data is sufficient to allow you to load the corresponding manager and retrieve the actual item.

To subscribe to the IDataEvent:

  1. In Visual Studio, in your project, open the Global.asax file.

    NOTE: If you do not have a Global.asax file, create a new Global.asax file and add it to your project. In the context menu of your project, click Add » New Item… » Visual C# » Web » Global Application Class..

  2. Add the following code:

    C#
    using System;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Data;
    using Telerik.Sitefinity.Data.Events;
    using Telerik.Sitefinity.Services;
    
    namespace SitefinityWebApp
    {
        public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
            }
    
            private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
            {
                EventHub.Subscribe<IDataEvent>(evt => DataEventHandler(evt));
            }
    
            public void DataEventHandler(IDataEvent eventInfo)
            {
                var action = eventInfo.Action;
                var contentType = eventInfo.ItemType;
                var itemId = eventInfo.ItemId;
                var providerName = eventInfo.ProviderName;
    
                var manager = ManagerBase.GetMappedManager(contentType, providerName);
                var item = manager.GetItemOrDefault(contentType, itemId);
            }
        }
    }

As a result you are subscribed to theIDataEvent and you can access the event's ID, provider name, action, item type. and so forth. You can modify the event's attributes, subscribe an email address to the event, and so on.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?