Пример #1
0
        public JsonResult Data(string deptNo, string keyword)
        {
            //获取 easyui-datagrid 的分页参数和排序参数
            var pager   = EasyUIHelper.GetDataPager();
            var sorting = EasyUIHelper.GetSorting();

            sorting.Replace(new Dictionary <string, string> {
                { "SexText", "Sex" }
            });

            using (var context = new DbContext())
            {
                //使用AssertWhere拼接linq
                var list = context.Employees
                           .Segment(pager)
                           .AssertWhere(!string.IsNullOrEmpty(deptNo), s => s.Dept.No.StartsWith(deptNo))
                           .AssertWhere(!string.IsNullOrEmpty(keyword), s => s.Name.Contains(keyword) || s.No.Contains(keyword))
                           .OrderBy(sorting, u => u.OrderBy(s => s.Name)) //默认按名称排序
                           .Select(s => s.Extend(() => new
                {
                    SexText = s.Sex.GetDescription()
                }))
                           .ToList();

                //如果使用Extend的话,UI不能使用SexText进行排序
                //另一种办法就是把需要显示到UI的属性都打出来
                // .Select(s => new { s.Id, s.Name, Sex = s.Sex.GetDescription() })

                //使用Transfer把列表转换成 easyui-datagrid 的json格式: { total: 10, rows: [{},{}] }
                //注意上面要用 ToList,不然 pager 的记录总数和页码数无法获取
                return(Json(EasyUIHelper.Transfer(pager, list)));
            }
        }
Пример #2
0
        public async Task <JsonResult> Data(string keyword, int?type, StateFlags?state)
        {
            var pager   = EasyUIHelper.GetDataPager();
            var sorting = EasyUIHelper.GetSorting();
            var list    = await adminService.GetRolesAsync(state, keyword, pager, sorting);

            return(Json(EasyUIHelper.Transfer(pager, list)));
        }
Пример #3
0
        /// <summary>
        /// 根据查询条件获取角色。
        /// </summary>
        /// <param name="state">启用状态</param>
        /// <param name="keyword">关键字</param>
        /// <returns></returns>
        public async Task <JsonResult> Data(StateFlags?state, string keyword)
        {
            var pager   = EasyUIHelper.GetDataPager(HttpContext);
            var sorting = EasyUIHelper.GetSorting(HttpContext);

            var list = await adminService.GetRolesAsync(state, keyword, pager, sorting);

            return(Json(list));
        }
Пример #4
0
        public async Task <JsonResult> Data(string orgCode, string keyword, StateFlags?state)
        {
            var pager   = EasyUIHelper.GetDataPager(HttpContext);
            var sorting = EasyUIHelper.GetSorting(HttpContext);

            var userId = HttpContext.GetSession().UserID;

            sorting = sorting.Replace("SexName", "Sex", "DegreeName", "DegreeNo", "TitleName", "TitleNo");

            var list = await _adminService.GetUsersAsync(userId, orgCode, state, keyword, pager, null);

            return(Json(EasyUIHelper.Transfer(pager, list)));
        }
Пример #5
0
        /// <summary>
        /// 根据查询条件获取用户。
        /// </summary>
        /// <param name="orgCode">机构编码</param>
        /// <param name="keyword">关键字</param>
        /// <param name="roleId">角色ID。</param>
        /// <param name="state">启用状态</param>
        /// <returns></returns>
        public async Task <JsonResult> GetUsers(string orgCode, string keyword, int roleId)
        {
            var pager   = EasyUIHelper.GetDataPager(HttpContext);
            var sorting = EasyUIHelper.GetSorting(HttpContext);

            var userId = HttpContext.GetSession().UserID;

            sorting = sorting.Replace("SexName", "Sex", "DegreeName", "DegreeNo", "TitleName", "TitleNo");

            var list = await _adminService.GetUsersByRoleExcludeAsync(userId, orgCode, roleId, keyword, pager, sorting);

            return(Json(EasyUIHelper.Transfer(pager, list)));
        }
Пример #6
0
        /// <summary>
        /// 根据角色获取相应的用户。
        /// </summary>
        /// <param name="roleId">角色ID。</param>
        /// <returns></returns>
        public async Task <JsonResult> GetUsersByRole(int?roleId)
        {
            if (roleId == null)
            {
                return(Json(new string[0]));
            }

            var pager   = EasyUIHelper.GetDataPager(HttpContext);
            var sorting = EasyUIHelper.GetSorting(HttpContext);

            var list = await _adminService.GetUsersByRoleAsync((int)roleId, pager, sorting);

            return(Json(EasyUIHelper.Transfer(pager, list)));
        }