Exemple #1
0
        /// <summary>
        /// 读取分页数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult <Page <User> > > GetPagesAsync(GetUserPagesRequest request)
        {
            return(await QueryResultAsync(async query =>
            {
                var rsp = new ApiResult <Page <User> >();

                var result = new Page <User>();

                // 如果通过用户组检索
                if (!string.IsNullOrEmpty(request.UserGroupId))
                {
                    result = await QueryNoTracking <UserGroupUser>()
                             .Include(p => p.User)
                             .Where(p => p.UserGroupId == request.UserGroupId)
                             .HasWhere(request.UserName, p => p.User.UserName.Contains(request.UserName))
                             .Select(p => p.User)
                             .ToPageAsync(request.PageIndex, request.PageSize);
                }
                // 通过角色组检索
                else if (!string.IsNullOrEmpty(request.RoleGroupId))
                {
                    result = await QueryNoTracking <RoleGroupUser>()
                             .Include(p => p.User)
                             .Where(p => p.RoleGroupId == request.RoleGroupId)
                             .HasWhere(request.UserName, p => p.User.UserName.Contains(request.UserName))
                             .Select(p => p.User)
                             .ToPageAsync(request.PageIndex, request.PageSize);
                }
                else
                {
                    result = await query
                             .HasWhere(request.UserName, p => p.UserName.Contains(request.UserName))
                             .ToPageAsync(request.PageIndex, request.PageSize);
                }
                if (result.Items.Count == 0)
                {
                    rsp.Message = "暂无数据.";
                    return rsp;
                }
                rsp.Message = "读取成功.";
                rsp.Data = result;
                rsp.Success = true;
                return rsp;
            }));
        }
Exemple #2
0
 public async Task <ApiResult <Page <User> > > GetPages([FromBody] GetUserPagesRequest request)
 {
     return(await _userService.GetPagesAsync(request));
 }