// Get the forum ForumInfo forum = ForumInfoProvider.GetForumInfo("MyNewForum", CMSContext.CurrentSiteID);
if (forum != null) { // Create new forum post object ForumPostInfo newPost = newForumPostInfo(); // Set the properties newPost.PostUserID = CMSContext.CurrentUser.UserID; newPost.PostUserMail = CMSContext.CurrentUser.Email; newPost.PostUserName = CMSContext.CurrentUser.UserName; newPost.PostForumID = forum.ForumID; newPost.PostTime = DateTime.Now; newPost.PostApproved = true; newPost.PostText = "This is my new post"; newPost.PostSubject = "My new post"; // Save the forum post ForumPostInfoProvider.SetForumPostInfo(newPost); returntrue; } returnfalse; }
The following example gets and updates a forum post.
privatebool GetAndUpdateForumPost() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10;
// Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns);
if (!DataHelper.DataSourceIsEmpty(posts)) { ForumPostInfo updatePost = newForumPostInfo(posts.Tables[0].Rows[0]); // Update the properties updatePost.PostSubject = updatePost.PostSubject.ToLower(); // Save the changes ForumPostInfoProvider.SetForumPostInfo(updatePost); returntrue; } returnfalse; }
The following example gets and bulk updates forum posts.
privatebool GetAndBulkUpdateForumPosts() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10;
// Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns);
if (!DataHelper.DataSourceIsEmpty(posts) { // Loop through the individual items foreach (DataRow postDr in posts.Tables[0].Rows) { // Create object from DataRow ForumPostInfo modifyPost = newForumPostInfo(postDr); // Update the properties modifyPost.PostSubject = modifyPost.PostSubject.ToUpper(); // Save the changes ForumPostInfoProvider.SetForumPostInfo(modifyPost); } returntrue; } returnfalse; }
The following example deletes a forum post.
privatebool DeleteForumPost() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10;
// Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns);
if (!DataHelper.DataSourceIsEmpty(posts)) { // Get the forum post ForumPostInfo deletePost = newForumPostInfo(posts.Tables[0].Rows[0]); // Delete the forum post ForumPostInfoProvider.DeleteForumPostInfo(deletePost); returntrue; } returnfalse; }