
using PageAdmin.Common;
using PageAdmin.Utils.ORM;
using PageAdmin.Utils;
using PageAdmin.Web.Filter;
using System.Collections;
using System.Collections.Generic;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class CacheManagerController :BaseController
    {
        public CacheManagerController() : base("Tool/")
        {
        }

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public virtual JsonResult PageListData()
        {
            var form = Request.QueryString;
            PageInfo pageInfo = new PageInfo();
            int currentPage = 1;
            if (StringHelper.IsInt(form["page"]))
            {
                currentPage = int.Parse(form["page"]);
                pageInfo.CurrentPage = currentPage;
            }
            int pageSize = pageInfo.PageSize;
            if (StringHelper.IsInt(form["pagesize"]))
            {
                pageSize = int.Parse(form["pagesize"]);
                pageInfo.PageSize = pageSize;
            }
            IEnumerable<Hashtable> dataList = CacheHelper.ListCache();
            dataList=IEnumerableHelper.Split(dataList,pageInfo);
            return Json(dataList,pageInfo);
        }

        [HttpPost]
        public JsonResult Delete(FormCollection form)
        {
            TipsInfo tipsInfo = new TipsInfo();
            string Name = form["name"];
            CacheHelper.Remove(Name);
            return Json(tipsInfo);
        }
    }
}