Forums


List of examples:

Forum groups

Creating a forum group




// Creates a new forum group object
ForumGroupInfo newGroup = new ForumGroupInfo();

// Sets the forum group properties
newGroup.GroupDisplayName = "New group";
newGroup.GroupName = "NewGroup";
newGroup.GroupSiteID = SiteContext.CurrentSiteID;
newGroup.GroupAuthorDelete = true;
newGroup.GroupAuthorEdit = true;
newGroup.GroupDisplayEmails = true;

// Saves the forum group to the database
ForumGroupInfoProvider.SetForumGroupInfo(newGroup);


> Back to list of examples

Updating a forum group




// Gets the forum group
ForumGroupInfo updateGroup = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);
if (updateGroup != null)
{
    // Updates the properties
    updateGroup.GroupDisplayName = updateGroup.GroupDisplayName.ToLower();

    // Saves the changes
    ForumGroupInfoProvider.SetForumGroupInfo(updateGroup);
}


> Back to list of examples

Updating multiple forum groups




// Prepares parameters for loading all forum groups whose name starts with 'NewGroup'
var where = new WhereCondition("GroupName", QueryOperator.Like, "NewGroup%");

// Gets the forum groups based on the parameters
var groups = ForumGroupInfoProvider.GetForumGroups().Where(where);

// Loops through individual groups
foreach (ForumGroupInfo forumGroup in groups)
{
    // Updates the properties
    forumGroup.GroupDisplayName = forumGroup.GroupDisplayName.ToUpper();

    // Saves the changes to the database
    ForumGroupInfoProvider.SetForumGroupInfo(forumGroup);
}


> Back to list of examples

Deleting a forum group




// Gets the forum group
ForumGroupInfo deleteGroup = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);

if (deleteGroup != null)
{
    // Deletes the forum group
    ForumGroupInfoProvider.DeleteForumGroupInfo(deleteGroup);
}


> Back to list of examples

Forums

Creating a forum




// Gets the parent forum group
ForumGroupInfo group = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);

if (group != null)
{
    // Creates a new forum object
    ForumInfo newForum = new ForumInfo();

    // Sets the forum properties
    newForum.ForumDisplayName = "New forum";
    newForum.ForumName = "NewForum";
    newForum.ForumGroupID = group.GroupID;
    newForum.ForumSiteID = group.GroupSiteID;
    newForum.AllowAccess = SecurityAccessEnum.AllUsers;
    newForum.AllowAttachFiles = SecurityAccessEnum.AuthenticatedUsers;
    newForum.AllowPost = SecurityAccessEnum.AllUsers;
    newForum.AllowReply = SecurityAccessEnum.AllUsers;
    newForum.AllowSubscribe = SecurityAccessEnum.AllUsers;
    newForum.ForumOpen = true;
    newForum.ForumModerated = false;
    newForum.ForumThreads = 0;
    newForum.ForumPosts = 0;

    // Saves the forum to the database
    ForumInfoProvider.SetForumInfo(newForum);
}


> Back to list of examples

Updating a forum




// Gets the forum
ForumInfo updateForum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);
if (updateForum != null)
{
    // Updates the properties
    updateForum.ForumDisplayName = updateForum.ForumDisplayName.ToLower();

    // Saves the changes to the database
    ForumInfoProvider.SetForumInfo(updateForum);
}


> Back to list of examples

Updating multiple forums




// Prepares parameters for loading the first 10 forums whose name starts with 'NewForum'
var where = new WhereCondition("ForumName", QueryOperator.Like, "NewForum%");
int topN = 10;

// Gets the forums based on the parameters
var forums = ForumInfoProvider.GetForums().Where(where).TopN(topN);

// Loops through individual forums
foreach (ForumInfo forum in forums)
{
    // Updates the properties
    forum.ForumDisplayName = forum.ForumDisplayName.ToUpper();

    // Saves the changes to the database
    ForumInfoProvider.SetForumInfo(forum);
}


> Back to list of examples

Deleting a forum




// Gets the forum
ForumInfo deleteForum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);

if (deleteForum != null)
{
    // Deletes the forum
    ForumInfoProvider.DeleteForumInfo(deleteForum);
}


> Back to list of examples

Forum posts

Creating a forum post




// Gets the forum
ForumInfo forum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);
if (forum != null)
{
    // Creates a new forum post object
    ForumPostInfo newPost = new ForumPostInfo();

    // Sets the forum post properties
    newPost.PostUserID = MembershipContext.AuthenticatedUser.UserID;
    newPost.PostUserMail = MembershipContext.AuthenticatedUser.Email;
    newPost.PostUserName = MembershipContext.AuthenticatedUser.UserName;
    newPost.PostForumID = forum.ForumID;
    newPost.SiteId = forum.ForumSiteID;
    newPost.PostTime = DateTime.Now;
    newPost.PostApproved = true;
    newPost.PostSubject = "New post";
    newPost.PostText = "This is a new post";

    // Saves the forum post to the database
    ForumPostInfoProvider.SetForumPostInfo(newPost);
}


> Back to list of examples

Updating multiple forum posts




// Prepares a condition for loading all forum posts whose subject starts with 'New post'
var where = new WhereCondition("PostSubject", QueryOperator.Like, "New post%");

// Gets the forum posts based on the condition
var posts = ForumPostInfoProvider.GetForumPosts().Where(where);

// Loops through individual forum posts
foreach (ForumPostInfo forumPost in posts)
{
    // Updates the forum post properties
    forumPost.PostSubject = forumPost.PostSubject.ToUpper();

    // Saves the changes to the database
    ForumPostInfoProvider.SetForumPostInfo(forumPost);
}


> Back to list of examples

Deleting forum posts




// Prepares a condition for loading all unapproved forum posts
var where = new WhereCondition("PostApproved", QueryOperator.Equals, 0);

// Gets all unapproved forum posts
var posts = ForumPostInfoProvider.GetForumPosts().Where(where);

// Loops through individual forum posts
foreach (ForumPostInfo forumPost in posts)
{
    if (forumPost != null)
    {
        // Deletes the forum post
        ForumPostInfoProvider.DeleteForumPostInfo(forumPost);
    }
}


> Back to list of examples