Пример #1
0
        /// <summary>
        /// 读取分页数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult <Page <Role> > > GetPagesAsync(GetRolePagesRequest request)
        {
            return(await QueryResultAsync(async query =>
            {
                var rsp = new ApiResult <Page <Role> >();

                var result = new Page <Role>();
                // 如果通过角色组检索
                if (!string.IsNullOrEmpty(request.RoleGroupId))
                {
                    result = await QueryNoTracking <RoleGroupRole>()
                             .Include(p => p.Role)
                             .Where(p => p.RoleGroupId == request.RoleGroupId)
                             .HasWhere(request.Name, p => p.Role.Name.Contains(request.Name))
                             .Select(p => p.Role)
                             .ToPageAsync(request.PageIndex, request.PageSize);
                }
                else
                {
                    result = await query
                             .HasWhere(request.Name, p => p.Name.Contains(request.Name))
                             .ToPageAsync(request.PageIndex, request.PageSize);
                }
                if (result.Items.Count == 0)
                {
                    rsp.Message = "暂无数据.";
                    return rsp;
                }
                rsp.Message = "读取成功.";
                rsp.Data = result;
                rsp.Success = true;
                return rsp;
            }));
        }
Пример #2
0
 public async Task <ApiResult <Page <Role> > > GetPages([FromBody] GetRolePagesRequest request)
 {
     return(await _roleService.GetPagesAsync(request));
 }