예제 #1
0
        public ActionResult <BaseResponse> QueryUserList(UserListRequest request)
        {
            var filters = new List <Expression <Func <User, bool> > >();

            if (!string.IsNullOrWhiteSpace(request.Name))
            {
                filters.Add(x => x.Name.Contains(request.Name));
            }

            if (request.Status > 0)
            {
                filters.Add(x => x.Status == request.Status);
            }

            var result = _accountStoreService.QueryUserListPage(request.PageIndex, request.PageSize, filters, x => x.CreateTime, false, out int total);

            var list = new List <UserDto>();

            foreach (var user in result)
            {
                var userDto = _mapper.Map <UserDto>(user);
                userDto.Roles = user.UserRoleRelations.Select(x => _mapper.Map <RoleDto>(x.Role)).Where(x => x.IsDelete == false).OrderBy(x => x.CreateTime).ToList();
                list.Add(userDto);
            }

            var pageData = new PageData <UserDto>()
            {
                PageIndex  = request.PageIndex,
                PageSize   = request.PageSize,
                TotalCount = total,
                List       = list
            };

            return(BaseResponse <PageData <UserDto> > .GetBaseResponse(pageData));
        }