Beispiel #1
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="parameter">查询参数</param>
        public async Task <PagerList <AdministratorResponse> > PagerQueryAsync(AdministratorQuery parameter)
        {
            if (parameter == null)
            {
                return(new PagerList <AdministratorResponse>());
            }
            Debug.WriteLine($"当前用户: {CurrentUser.UserId}, {CurrentUser.UserName}");
            var query = SqlQuery
                        .Select <User>(
                x => new object[] { x.Id, x.Nickname, x.UserName, x.LastModificationTime, x.LastModifier },
                true)
                        .Select <UserInfo>(x => new object[] { x.Gender })
                        .Select <Administrator>(x => new object[] { x.Enabled })
                        .From <User>("a")
                        .Join <UserInfo>("b").On <User, UserInfo>((l, r) => l.Id == r.Id)
                        .Join <Administrator>("c").On <User, Administrator>((l, r) => l.Id == r.Id)
                        .WhereIfNotEmpty <User>(x => x.Nickname.Contains(parameter.Nickname))
                        .WhereIf <User>(x => x.Enabled, parameter.Enabled, parameter.Enabled.HasValue);

            if (!parameter.RoleId.IsEmpty())
            {
                query.Join(
                    x =>
                {
                    x.Select <UserRole>(y => new object[] { y.UserId }, true).From <UserRole>()
                    .Where <UserRole>(y => y.RoleId == parameter.RoleId);
                }, "d").AppendOn("a.UserId = d.UserId");
            }
            var result = await query
                         .OrderBy <User>(x => x.LastModificationTime)
                         .ToPagerListAsync <AdministratorResponse>(parameter);

            var userIds   = result.Data.Select(x => Conv.ToGuid(x.Id)).ToList();
            var userRoles = await GetUserRolesAsync(userIds);

            if (userRoles.Any())
            {
                result.Data.ForEach(x => { x.Roles = userRoles.Where(y => y.UserId.ToString() == x.Id).ToList(); });
            }
            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> PagerQueryAsync([FromQuery] AdministratorQuery query)
        {
            var result = await QueryAdministratorService.PagerQueryAsync(query);

            return(Success(result));
        }