using PageAdmin.BLL;
using PageAdmin.Utils;
using System;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    //[GetAdminMenu("index","get")]
    public class RolePermissionsController : SetDataBaseController
    {
        public RolePermissionsController() : base("pa_role_permissions", "User/Role/")
        {
            base.IndexViewExecuting = new Action(OnGetDataing);
            base.EditExecuting = SetMenuIds;
        }

        /// <summary>
        /// 给菜单自动添加上级menuIds
        /// </summary>
        private void SetMenuIds()
        {
            string menuIds = base.MvcContext.Data["MenuIds"];
            AdminMenuBLL adminMenuBLL = new AdminMenuBLL();
            menuIds = adminMenuBLL.GetParentIdsAdnSelf(menuIds);
            base.MvcContext.Data["MenuIds"] = menuIds;
        }

        private void OnGetDataing()
        {
            int roleId = StringHelper.Format<int>(Request.QueryString["roleId"]);
            if (roleId == 0)
            {
                throw new Exception("无效的roleId参数！");
            }
            RoleBLL roleBll = new RoleBLL();
            if (!roleBll.IsExists(roleId))
            {
                throw new Exception("roleId参数值错误！");
            }
            base.GetDataWhere = "roleId=" + roleId;
            base.AddDbKeyValueList.Add("roleId", roleId);
        }

    }
}