using Learun.Application.Organization;
using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
using System.Collections.Generic;
using System.Web.Mvc;

namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创建人：研发部
    /// 日 期：2017.03.09
    /// 描 述：角色管理
    /// </summary>
    public class RoleController : MvcControllerBase
    {
        private RoleIBLL roleIBLL = new RoleBLL();

        #region 获取视图
        /// <summary>
        /// 主页
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 表单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Form()
        {
            return View();
        }

        public ActionResult RoleForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取角色列表信息
        /// </summary>
        /// <param name="keyWord">查询关键字</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetList(string keyword, string ProjectId)
        {
            var data = roleIBLL.GetList(keyword, ProjectId);
            return Success(data);
        }

        /// <summary>
        /// 获取角色列表信息Tree
        /// </summary>
        /// <param name="ProjectId">查询关键字</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetTreeList(string ProjectId)
        {
            var data = roleIBLL.GetList(ProjectId);

            List<TreeModel> treeList = new List<TreeModel>();
            foreach (var item in data)
            {
                TreeModel node = new TreeModel();
                node.id = item.F_RoleId;
                node.text = item.F_FullName;
                node.value = item.F_RoleId;
                node.showcheck = false;
                node.checkstate = 0;
                node.isexpand = false;
                node.parentId = "0";
                node.NodeExtData = item;
                treeList.Add(node);
            }
            return Success(treeList);
        }
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetPageList(string pagination, string queryJson)
        {
            Pagination paginationobj = pagination.ToObject<Pagination>();
            var data = roleIBLL.GetPageList(paginationobj, queryJson);
            var jsonData = new
            {
                rows = data,
                total = paginationobj.total,
                page = paginationobj.page,
                records = paginationobj.records,
            };
            return Success(jsonData);
        }
        /// <summary>
        /// 获取角色列表（所有）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetRoleList()
        {
            var data = roleIBLL.GetList("");
            return Success(data);
        }

        /// <summary>
        /// 获取表单数据
        /// <summary>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetFormData(string keyValue)
        {
            var RoleEntitydata = roleIBLL.GetEntity(keyValue);
            var jsonData = new
            {
                RoleEntity = RoleEntitydata,
            };
            return Success(jsonData);
        }
        #endregion

        #region 提交数据
        /// <summary>
        /// 保存表单数据
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult SaveForm(string keyValue, RoleEntity entity)
        {
            roleIBLL.SaveEntity(keyValue, ref entity);
            return Success("保存成功！");
        }
        /// <summary>
        /// 删除表单数据
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult DeleteForm(string keyValue)
        {
            roleIBLL.VirtualDelete(keyValue);
            return Success("删除成功！");
        }
        #endregion
    }
}