Esempio n. 1
0
        /// <summary>
        /// 用户获取
        /// 这里主要演示内容:
        /// FreeSql:
        /// 分页
        /// WhereIf
        /// 一对一 多对多查询
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <PageListBase <UserVO> > GetUserPageAsync(UserPageParam param)
        {
            #region 贪婪加载 Include/IncludeMany 条件筛选 WhereIf 排序(字符串) OrderBy("string") 分页 Page() 返回条数 Count()
            var userList = await _userRep.Select
                           .Include(x => x.UserInfo)
                           .IncludeMany(x => x.UserRoles, next => next.Include(ur => ur.Role))
                           .Include(x => x.Terant)
                           .WhereIf(!string.IsNullOrWhiteSpace(param.KeyWord),
                                    x => param.KeyWord.Contains(x.RealName))
                           .WhereIf(param.RoleIds?.Any() ?? false, x => x.UserRoles.Any(r => param.RoleIds.Contains(r.RoleId)))
                           .WhereIf(param.IsDelete != null, x => x.IsDeleted == param.IsDelete)
                           .Count(out var total)//total是long型的
                           .OrderBy(param.OrderBy)
                           .Page(param.PageIndex + 1, param.PageSize)
                           .ToListAsync(true);

            #endregion
            return(new PageListBase <UserVO>(Mapper.Map <List <UserVO> >(userList), total, param.PageIndex + 1, param.PageSize));
        }
Esempio n. 2
0
 public async Task <IActionResult> GetUserPage([FromQuery] UserPageParam param)
 {
     return(Ok(await _commonService.GetUserPageAsync(param)));
 }