Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

Eucalypto - ASP.NET CMS Library using NHibernate

Rate me:
Please Sign up or sign in to vote.
4.84/5 (36 votes)
10 Jun 2009MIT24 min read 318.5K   4.6K   260  
An ASP.NET server library for creating CMS website (forums, articles/wiki, news, users/roles, ...), using NHibernate for data access.
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

public partial class Controls_TopicList : System.Web.UI.UserControl
{
    private const int LIST_PAGING_SIZE = 10;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            LoadList();
        }
    }

    #region Properties
    /// <summary>
    /// Gets or sets the forum category name used to load the list of topics
    /// </summary>
    public string CategoryName
    {
        get
        {
            object val = ViewState["CategoryName"];
            return val == null ? null : (string)val;
        }
        set { ViewState["CategoryName"] = value; }
    }

    /// <summary>
    /// The page used for the list pagination.
    /// </summary>
    protected int CurrentPage
    {
        get
        {
            object val = ViewState["CurrentPage"];
            return val == null ? 0 : (int)val;
        }
        set { ViewState["CurrentPage"] = value; }
    }
    #endregion

    private void LoadList()
    {
        Eucalypto.Forum.Category category = Eucalypto.Forum.ForumManager.GetCategoryByName(CategoryName, true);

        Eucalypto.PagingInfo paging = new Eucalypto.PagingInfo(LIST_PAGING_SIZE, CurrentPage);
        IList<Eucalypto.Forum.Topic> topics = Eucalypto.Forum.ForumManager.GetTopics(category,
                                                    paging);


        lblCurrentPage.Text = (CurrentPage + 1).ToString();
        lblTotalPage.Text = paging.PagesCount.ToString();

        listRepeater.DataSource = topics;
        listRepeater.DataBind();

        if (CurrentPage == 0)
            linkPrev.Enabled = false;
        else
            linkPrev.Enabled = true;
        if (CurrentPage + 1 >= paging.PagesCount)
            linkNext.Enabled = false;
        else
            linkNext.Enabled = true;
    }

    protected string GetViewTopicUrl(string idTopic)
    {
        return Navigation.Forum_ViewTopic(idTopic).GetClientUrl(this);
    }

    protected int GetRepliesCount(string idTopic)
    {
        Eucalypto.Forum.Topic topic = Eucalypto.Forum.ForumManager.GetTopic(idTopic);

        //Remove 1 because it is the topic message
        return Eucalypto.Forum.ForumManager.MessageCountByTopic(topic) - 1;
    }

    protected void linkPrev_Click(object sender, EventArgs e)
    {
        CurrentPage--;
        LoadList();
    }
    protected void linkNext_Click(object sender, EventArgs e)
    {
        CurrentPage++;
        LoadList();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions