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

namespace PageAdmin.Web.Areas.E.Views.SubData.Filter
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true)]
    public class CheckDetailId : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var  request = filterContext.HttpContext.Request.QueryString;
            string table = StringHelper.Format<string>(request["table"]);
            if (string.IsNullOrEmpty(table))
            {
                Error(filterContext, "table参数错误！");
                return;
            }
            SubTableBLL subTableBLL = new SubTableBLL();
            if(!subTableBLL.IsExists(table))
            {
                Error(filterContext, "当前表不是附属表！");
                return;
            }
        }

        public void Error(ActionExecutingContext filterContext,string content)
        {
            filterContext.Result = new ContentResult
            {
                ContentType = "application/json",
                Content = "{\"State\":0,\"Msg\":\""+ content+"\"}"
            };
        }
    }
}