Example #1
0
        public async Task <PageResult> GetPageListAsync(int deptId, PageOption pageOption, string strSearch = null)
        {
            Expression <Func <Sys_User, bool> > exp = p => true;

            if (!string.IsNullOrEmpty(strSearch))
            {
                exp = exp.And(p =>
                              p.ID.ToString().Contains(strSearch) ||
                              p.Name.Contains(strSearch) ||
                              p.LoginName.Contains(strSearch) ||
                              p.Code.Contains(strSearch));
            }
            IQueryable <UserDto> query = null;

            if (deptId == 0)
            {
                query = from user in _unitOfWork.SysUserRep.Query.Where(exp)
                        join i in _unitOfWork.SysDeptRep.Query
                        on user.DeptID equals i.ID into list
                        from dept in list.DefaultIfEmpty()
                        select new UserDto
                {
                    UserID    = user.ID,
                    UserName  = user.Name,
                    DeptID    = user.DeptID,
                    DeptName  = dept.Name,
                    Code      = user.Code,
                    LoginName = user.LoginName,
                    Sex       = user.Sex,
                    Remark    = user.Remark
                };
            }
            else
            {
                var deptService = new DeptService(_unitOfWork);
                var deptList    = new List <DeptDto>();
                deptList.Add(deptService.Init(deptId).Data);
                deptService.GetDeptByParentId(deptList, deptId);
                query = from user in _unitOfWork.SysUserRep.Query.Where(exp)
                        join dept in deptList
                        on user.DeptID equals dept.DeptID
                        select new UserDto
                {
                    UserID    = user.ID,
                    UserName  = user.Name,
                    DeptID    = user.DeptID,
                    DeptName  = dept.DeptName,
                    Code      = user.Code,
                    LoginName = user.LoginName,
                    Sex       = user.Sex,
                    Remark    = user.Remark
                };
            }
            return(await query.ToPageResultAsync(pageOption));
        }