using PageAdmin.BLL;
using PageAdmin.Utils;
using System;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class AdminMenuItemController : DefaultBaseController
    {
        public AdminMenuItemController() : base("pa_admin_menu_item", "System/Configure/AdminMenu")
        {
            base.IndexViewExecuting = new Action(GetWhere);
            base.ListDataExecuting = new Action(GetWhere);
            base.DeleteExecuting = ()=>{ base.MvcContext.SqlCondition = "isDefault=0"; };
        }

        private void GetWhere()
        {
            int menuId = StringHelper.Format<int>(Request.QueryString["menuId"]);
            if (menuId<=0)
            {
                throw new Exception("无效的menuId参数!");
            }
            base.MvcContext.SqlCondition = "menuId=" + menuId;
            base.MvcContext.ListOrder = "id asc";
        }

        [HttpGet]
        public JsonResult GetCheckBoxList()
        {
            AdminMenuItemBLL adminMenuItemBll = new AdminMenuItemBLL();
            var data = adminMenuItemBll.LoadItem();
            return Json(data);
        }

    }
}