Created
July 12, 2016 14:52
-
-
Save ivaneftimov/63ca2a92fc9520c655b7e9f0322b35e2 to your computer and use it in GitHub Desktop.
Sitefinity events - Susbscribe/unsubscribe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Global.asax.cs | |
| using System; | |
| using System.Web; | |
| using Telerik.Sitefinity.Abstractions; | |
| using Telerik.Sitefinity.Blogs.Model; | |
| using Telerik.Sitefinity.Data; | |
| using Telerik.Sitefinity.Data.Events; | |
| using Telerik.Sitefinity.Modules.Blogs; | |
| using Telerik.Sitefinity.Services; | |
| namespace SitefinityWebApp | |
| { | |
| public class Global : HttpApplication | |
| { | |
| protected void Application_Start(object sender, EventArgs e) | |
| { | |
| Bootstrapper.Initialized += this.Bootstrapper_Initialized; | |
| } | |
| protected void Application_End(object sender, EventArgs e) | |
| { | |
| EventHub.Unsubscribe<IDataEvent>(this.OnBlogPostCreated); | |
| } | |
| private void Bootstrapper_Initialized(object sender, ExecutedEventArgs e) | |
| { | |
| if (e.CommandName == "Bootstrapped") | |
| { | |
| EventHub.Subscribe<IDataEvent>(this.OnBlogPostCreated); | |
| } | |
| } | |
| private void OnBlogPostCreated(IDataEvent @event) | |
| { | |
| if (@event.ItemType == typeof(BlogPost) && @event.Action == "New") | |
| { | |
| var blogsManager = BlogsManager.GetManager(@event.ProviderName); | |
| var currentBlogPost = blogsManager.GetBlogPost(@event.ItemId); | |
| currentBlogPost.Content = currentBlogPost + "<br/><i>This is the disclaimer!</i>"; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment