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
}
}