using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace AppLibs.Libs
{
    public class PageInforAttribute : Attribute, IActionFilter
    {
        private string _pageID;
        private string _pageName;
        private string _flexPage;

        public PageInforAttribute(string pageID, string pageName)
        {
            this._pageID = pageID;
            this._pageName = pageName;
        }

        public PageInforAttribute(string pageID, string pageName, string flexPage) : this(pageID, pageName)
        {
            this._flexPage = flexPage;

        }
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Controller? controller = context.Controller as Controller;
            if (controller != null)
            {
                controller.ViewData["PageID"] = this._pageID;
                controller.ViewData["Title"] = this._pageName;
                controller.ViewData["FlexPage"] = this._flexPage;
            }
        }
    }
}
