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

Open Source Extensible Enterprise n-tier Application Framework with Multilayered Architecture

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
3 Dec 2010MIT3 min read 36.9K   770   41  
Xenta architecture overview
using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using SiberTek.Xenta.Presentation.Presenters;
using SiberTek.Xenta.Presentation.Resources;
using SiberTek.Xenta.Presentation.Utils;
using SiberTek.Xenta.Presentation.Views;
using SiberTek.Xenta.Web.Controls;
using SiberTek.Xenta.Web.Utils;

namespace SiberTek.Xenta.Web.Admin.Modules
{
    public partial class ForumRoleMap : ViewBase<RolePresenter>, IGrid, ICommandHandler
    {
        #region Properties
        [Browsable(false)]
        public int ForumID
        {
            get
            {
                return Convert.ToInt32(ViewState["ForumID"]);
            }
            set
            {
                ViewState["ForumID"] = value;
            }
        }

        public int RowCount
        {
            get
            {
                return gvForumRoleMap.Rows.Count;
            }
        }
        #endregion

        #region Methods
        public override void BindData()
        {
            DataContainer["ShowHidden"] = true;

            Presenter.LoadCollection();

            gvForumRoleMap.DataSource = DataContainer["RoleCollection"];
            gvForumRoleMap.DataBind();

            base.BindData();
        }

        public void SetColumnVisibility(int index, bool value)
        {
            if(index >= 0 && index < gvForumRoleMap.Columns.Count)
            {
                gvForumRoleMap.Columns[index].Visible = value;
            }
        }
        #endregion

        #region Handlers
        protected override void OnInit(EventArgs e)
        {
            if(!IsPostBack)
            {
                gvForumRoleMap.Columns[0].HeaderText = StringManager.GetString("Admin.ForumRoleMap.colMapped.HeaderText");
                gvForumRoleMap.Columns[1].HeaderText = StringManager.GetString("Admin.ForumRoleMap.colRole.HeaderText");
                gvForumRoleMap.Columns[2].HeaderText = StringManager.GetString("Admin.ForumRoleMap.colActive.HeaderText");
                gvForumRoleMap.EmptyDataText = StringManager.GetString("Admin.ForumRoleMap.EmptyDataText");
            }
            base.OnInit(e);
        }

        protected void GvForumRoleMap_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;

            if(row.RowType == DataControlRowType.DataRow)
            {
                ViewDataContainer item = e.Row.DataItem as ViewDataContainer;

                if(item != null)
                {
                    HiddenField hfRoleID = row.FindControl("hfRoleID") as HiddenField;
                    HyperLink lnkRole = row.FindControl("lnkRole") as HyperLink;
                    CheckBox cbIsActive = row.FindControl("cbIsActive") as CheckBox;
                    CheckBox cbIsMapped = row.FindControl("cbIsMapped") as CheckBox;

                    hfRoleID.Value = item["RoleID"].ToString();
                    lnkRole.Text = (string)item["Name"];
                    lnkRole.NavigateUrl = UrlHelper.FormatUrl("admin", "membership/roles/{0}.aspx", item["RoleID"]);
                    lnkRole.ToolTip = StringManager.GetString("Admin.ForumRoleMap.lnkRole.ToolTip");
                    cbIsMapped.Checked = ForumHelper.IsRoleAssignedToForum(ForumID, (int)item["RoleID"]);
                    cbIsActive.Checked = (bool)item["IsActive"];
                }
            }
        }

        public void OnCommand(object sender, CommandEventArgs e)
        {
            switch(e.CommandName)
            {
                case "Update":
                    {
                        try
                        {
                            foreach(GridViewRow row in gvForumRoleMap.Rows)
                            {
                                HiddenField hfRoleID = row.FindControl("hfRoleID") as HiddenField;
                                CheckBox cbIsMapped = row.FindControl("cbIsMapped") as CheckBox;

                                int roleID = Int32.Parse(hfRoleID.Value);

                                if(cbIsMapped.Checked)
                                {
                                    ForumHelper.AssignRoleToForum(ForumID, roleID);
                                }
                                else
                                {
                                    ForumHelper.UnassignRoleFromForum(ForumID, roleID);
                                }
                            }
                        }
                        catch(Exception ex)
                        {
                            Page.ShowMessage(ex.Message);
                        }
                    }
                    break;
            }
        }
        #endregion
    }
}

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
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions