Пример #1
0
        public JsonResult Page(int pageIndex, int pageSize, string name, string inRole, string outRole, int?deptID)
        {
            var sql = Sql.Builder.Where("is_super_user=0 and (real_name like @0 or user_name like @0)", "%" + name + "%");

            if (!string.IsNullOrEmpty(inRole))
            {
                sql.Where("role_id = @0", inRole.ToInt());
            }
            else if (!string.IsNullOrEmpty(outRole))
            {
                sql.Where("role_id <> @0", outRole.ToInt());
            }

            if (deptID.HasValue)
            {
                sql.Where("dept_id in (@0)", BasicDataCache.GetSubDepts(deptID.Value).Select(d => d.ID));
            }

            var page = SysUser.Page(pageIndex, pageSize, sql);

            return(Json(new ResponseData
            {
                Total = page.TotalItems,
                Data = page.Items.Select(user => new
                {
                    user.ID,
                    user.Email,
                    user.UserName,
                    user.RealName,
                    user.Phone,
                    user.EmployedDate,
                    DeptName = user.DeptID.ToDept().GetFullDeptName(),
                    RoleName = user.RoleID.ToRole().Name
                })
            }));
        }