Click here to Skip to main content
15,898,035 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 322K   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;

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

    protected void Page_Load(object sender, EventArgs e)
    {
        searchResult.LinkNextClick += new EventHandler(searchResult_LinkNextClick);
        searchResult.LinkPreviousClick += new EventHandler(searchResult_LinkPreviousClick);
        searchResult.SearchEntityUrlCallback += new Controls_SearchResult.SearchEntityUrlDelegate(searchResult_SearchEntityUrlCallback);

        if (IsPostBack == false)
        {
            LoadForums();
        }
    }

    private void LoadForums()
    {
        IList<Eucalypto.Forum.Category> forums = Eucalypto.Forum.ForumManager.GetAllCategories();
        listForum.Items.Clear();

        foreach (Eucalypto.Forum.Category category in forums)
        {
            if (Eucalypto.SecurityHelper.CanRead(User, category, null))
            {
                ListItem listItem = new ListItem(category.DisplayName);
                listItem.Selected = true;
                listItem.Value = category.Id;


                listForum.Items.Add(listItem);
            }
        }
    }

    private string[] GetSelectedForums()
    {
        List<string> forums = new List<string>();

        foreach (ListItem item in listForum.Items)
        {
            if (item.Selected)
            {
                Eucalypto.Forum.Category category = Eucalypto.Forum.ForumManager.GetCategory(item.Value);
                if (Eucalypto.SecurityHelper.CanRead(User, category, null))
                {
                    forums.Add(category.Name);
                }
            }
        }

        return forums.ToArray();
    }

    void searchResult_LinkPreviousClick(object sender, EventArgs e)
    {
        LoadList(searchResult.CurrentPage - 1);
    }

    void searchResult_LinkNextClick(object sender, EventArgs e)
    {
        LoadList(searchResult.CurrentPage + 1);
    }

    Navigation.NavigationPage searchResult_SearchEntityUrlCallback(Eucalypto.ISearchResult entity)
    {
        Eucalypto.Forum.Message msg = (Eucalypto.Forum.Message)entity;

        return Navigation.Forum_ViewTopic(msg.Topic.Id, msg.Id);
    }


    protected void btSearch_Click(object sender, EventArgs e)
    {
        LoadList(0);
    }

    private void LoadList(int page)
    {
        try
        {
            string[] searchFor = Eucalypto.SplitHelper.SplitSearchText(txtSearchFor.Text);
            string[] authorSearch = Eucalypto.SplitHelper.SplitSearchText(txtAuthor.Text);

            Eucalypto.PagingInfo paging = new Eucalypto.PagingInfo(LIST_PAGING_SIZE, page);
            IList<Eucalypto.Forum.Message> messages = Eucalypto.Forum.ForumManager.FindMessages(
                                                            Eucalypto.Filter.MatchOne( GetSelectedForums() ),
                                                            Eucalypto.Filter.ContainsAll( searchFor ), 
                                                            Eucalypto.Filter.ContainsOne( authorSearch ),
                                                            null,
                                                            null, null, 
                                                            paging);

            searchResult.LoadList(messages, page, (int)paging.PagesCount);
        }
        catch (Exception ex)
        {
            ((IErrorMessage)Master).SetError(GetType(), ex);
        }
    }
}

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