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 MyIssueDataController : DefaultBaseController
    {
        public MyIssueDataController() : base("pa_issue_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 = "id desc";
            }
        }


        [HttpGet]
        public ActionResult Issue()
        {
            var data =base.DetailData();
            WorkflowNodeBLL workflowNodeBLL = new WorkflowNodeBLL();
            ViewBag.WorkFlowNodeData = workflowNodeBLL.GetData(data.workflow_node_id);
            return View(data);
        }

        [AjaxOnly]
        [HttpPost]
        public JsonResult Issue(FormCollection form)
        {
            MvcContext.Data = form;
            IssueBLL issueBll = new IssueBLL();
            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))
            {
                issueBll.Issue(MvcContext);
            }
            else
            {
                tipsInfo.State = 0;
                tipsInfo.Msg = "无效的id或ids参数！";
            }
            return Json(tipsInfo);
        }

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

    }
}