private void ForumThread_BeforeCreate(ForumThreadBeforeCreateEventArgs args) { String originalContentId = System.Web.HttpContext.Current.Request["originalContentId"]; String originalContentTypeId = System.Web.HttpContext.Current.Request["originalContentTypeId"]; Guid originalContentGuid; Guid originalContentTypeGuid; if (!String.IsNullOrEmpty(originalContentId) && !String.IsNullOrEmpty(originalContentTypeId) && Guid.TryParse(originalContentId, out originalContentGuid) && Guid.TryParse(originalContentTypeId, out originalContentTypeGuid)) { if(originalContentTypeGuid == PublicApi.BlogPosts.ContentTypeId) { Entities.BlogPost blogPost = PublicApi.BlogPosts.Get(originalContentGuid); // Add the new forum post to the list of discussions started from this blog post Entities.ExtendedAttribute forumPosts = blogPost.ExtendedAttributes.Get("forumDiscussions"); if(forumPosts == null) { blogPost.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "forumDiscussions", Value = args.ContentId.ToString() }); } else { forumPosts.Value = new StringBuilder(forumPosts.Value).Append(",").Append(args.ContentId.ToString()).ToString(); } PublicApi.BlogPosts.Update(blogPost.Id.Value, new BlogPostsUpdateOptions() { ExtendedAttributes = blogPost.ExtendedAttributes }); // Add the blog post as the originator of the forum post args.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "createdFrom", Value = blogPost.ContentId.ToString() }); } else if(originalContentTypeGuid == PublicApi.WikiPages.ContentTypeId) { Entities.WikiPage wikiPage = PublicApi.WikiPages.Get(originalContentGuid); args.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "createdFrom", Value = wikiPage.ContentId.ToString() }); } } }
private void ForumThread_BeforeCreate(ForumThreadBeforeCreateEventArgs args) { String originalContentId = System.Web.HttpContext.Current.Request["originalContentId"]; String originalContentTypeId = System.Web.HttpContext.Current.Request["originalContentTypeId"]; Guid originalContentGuid; Guid originalContentTypeGuid; if (!String.IsNullOrEmpty(originalContentId) && !String.IsNullOrEmpty(originalContentTypeId) && Guid.TryParse(originalContentId, out originalContentGuid) && Guid.TryParse(originalContentTypeId, out originalContentTypeGuid)) { if (originalContentTypeGuid == PublicApi.BlogPosts.ContentTypeId) { Entities.BlogPost blogPost = PublicApi.BlogPosts.Get(originalContentGuid); // Add the new forum post to the list of discussions started from this blog post Entities.ExtendedAttribute forumPosts = blogPost.ExtendedAttributes.Get("forumDiscussions"); if (forumPosts == null) { blogPost.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "forumDiscussions", Value = args.ContentId.ToString() }); } else { forumPosts.Value = new StringBuilder(forumPosts.Value).Append(",").Append(args.ContentId.ToString()).ToString(); } PublicApi.BlogPosts.Update(blogPost.Id.Value, new BlogPostsUpdateOptions() { ExtendedAttributes = blogPost.ExtendedAttributes }); // Add the blog post as the originator of the forum post args.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "createdFrom", Value = blogPost.ContentId.ToString() }); } else if (originalContentTypeGuid == PublicApi.WikiPages.ContentTypeId) { Entities.WikiPage wikiPage = PublicApi.WikiPages.Get(originalContentGuid); args.ExtendedAttributes.Add(new Entities.ExtendedAttribute() { Key = "createdFrom", Value = wikiPage.ContentId.ToString() }); } } }