using PageAdmin.BLL;using PageAdmin.Filter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PageAdmin.Common;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class MySignDataController :DefaultBaseController
    {
        public MySignDataController():base("pa_sign_data_uid", "Work/")
        {
            base.ListDataExecuting = SetListWhere;
        }

        private void SetListWhere()
        {
            string action= RouteData.Values["action"].ToString();
            if(action=="PageListData")
            {
                int uid = base.CurrentUser.Uid;
                base.MvcContext.SqlCondition = "uid=" + uid;
                base.MvcContext.ListOrder = "start_date desc";
            }
            else if (action == "ListData")
            {
                base.MvcContext.ListOrder = "sign_date desc";
                string table = StringHelper.Format<string>(Request.QueryString["table"]);
                int detailId = StringHelper.Format<int>(Request.QueryString["detail_id"]);
                base.MvcContext.SqlCondition = "[table]='" + StringHelper.SqlFormat(table)+"' and detail_id="+ detailId;
            }

        }

        [HttpGet]
        public ActionResult Detail()
        {
            var data = JsonHelper.JsonParse(base.DetailData());
            return View((object)data);
        }

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

        [HttpGet]
        public ActionResult Sign()
        {
            var data =JsonHelper.JsonParse(base.DetailData());
            return View((object)data);
        }

        [AjaxOnly]
        [HttpPost]
        public JsonResult Sign(FormCollection form)
        {
            MvcContext.Data = form;
            SignDataUidBLL signDataUidBLL = new SignDataUidBLL();
            string ids=StringHelper.Format<string>(form["ids"]);
            string id = StringHelper.Format<string>(form["id"]);
            TipsInfo tipsInfo = base.MvcContext.TipsInfo;
            if(!string.IsNullOrEmpty(ids) ||  !string.IsNullOrEmpty(id))
            {
               signDataUidBLL.Sign(MvcContext);
            }
            else
            {
               tipsInfo.State = 0;
               tipsInfo.Msg = "无效的id或ids参数！";
            }
            return Json(tipsInfo);
        }
    }
}