using PageAdmin.BLL;
using PageAdmin.Common;
using PageAdmin.Utils;
using PageAdmin.Web.Filter;
using System.Linq;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class AccessKeyController : DefaultBaseController
    {
        public AccessKeyController() : base("pa_accessKey", "System/Configure/")
        {
            base.MvcContext.ListOrder = "id asc";
            base.AddViewExecuting = GetAccessKey;
            base.AddViewExecuting += GetWebApiList;
            base.EditViewExecuting = GetWebApiList;
        }

        private void GetAccessKey()
        {
            ViewBag.AccessKeySecret= SysHelper.NewGuid();
            string guid = SysHelper.NewGuid();
            ViewBag.AccessKeyId ="ak"+EncryptHelper.MD5(guid).Substring(8,16);
        }
        
        private void GetWebApiList()
        {
            ApiAdminBLL apiAdminBLL = new ApiAdminBLL();
            ViewBag.WebApiList = JsonHelper.JsonParse(apiAdminBLL.WebApiMethods.Select(c => new { Id = c.Name,Name=c.Name+"："+c.Remark }));
        }
    }
}