Ejemplo n.º 1
0
        public async Task <(IList <Account> Accounts, int TotalCount)> GetList(AccountListPagedRequestDto requestDto)
        {
            var queryable = _dbContext.Accounts
                            .Where(w => w.IsDeleted == requestDto.IsDeleted);

            if (!string.IsNullOrEmpty(requestDto.Vague))
            {
                queryable = queryable
                            .Where(w => w.Id.ToString() == requestDto.Vague ||
                                   EF.Functions.Like(w.Name, "%" + requestDto.Vague + "%") ||
                                   EF.Functions.Like(w.Username, "%" + requestDto.Vague + "%")
                                   );
            }
            if (requestDto.Status == 1)
            {
                queryable = queryable.Where(w => w.Status == AccountStatus.Normal);
            }
            if (requestDto.Status == 2)
            {
                queryable = queryable.Where(w => w.Status == AccountStatus.NotAllowedLogin);
            }

            var result = queryable.OrderByDescending(p => p.CreateTime);
            var list   = await result.Skip((requestDto.SkipPage - 1) *requestDto.PagedCount).Take(requestDto.PagedCount).ToListAsync();

            return(Mapper.Map <List <Account> >(list), result.Count());
        }
Ejemplo n.º 2
0
        public async Task <(IList <Account> Accounts, int TotalCount)> GetList(AccountListPagedRequestDto requestDto)
        {
            var list = await this.GetList();

            var queryable = list.Where(w => w.IsDeleted == requestDto.IsDeleted);

            if (!string.IsNullOrEmpty(requestDto.Vague))
            {
                queryable = queryable
                            .Where(w => w.Id.ToString() == requestDto.Vague ||
                                   w.Name.Contains(requestDto.Vague) ||
                                   w.Username.Contains(requestDto.Vague)
                                   );
            }
            if (requestDto.Status == 1)
            {
                queryable = queryable.Where(w => w.Status == AccountStatus.Normal);
            }
            if (requestDto.Status == 2)
            {
                queryable = queryable.Where(w => w.Status == AccountStatus.NotAllowedLogin);
            }

            var result = queryable.OrderByDescending(p => p.CreateInfo.CreateTime);

            return(result.Skip((requestDto.SkipPage - 1) * requestDto.PagedCount).Take(requestDto.PagedCount).ToList(), result.Count());
        }
Ejemplo n.º 3
0
        public async Task <ResultPagedList <AccountInfoBaseResponseDto> > GetList([FromBody] AccountListPagedRequestDto dto)
        {
            //验证请求数据合法性
            var result = dto.Valid();

            if (!result.Success)
            {
                return(ResultPagedList <AccountInfoBaseResponseDto> .ReFailure(result));
            }

            //获取用户数据
            var accountsResult = await _accountRepository.GetList(dto);

            var accounts = accountsResult.Accounts;

            if (accounts.Count == 0)
            {
                return(ResultPagedList <AccountInfoBaseResponseDto> .ReSuccess());
            }

            //获取角色数据
            var rids = new List <int>();

            accounts
            .Select(f => f.Roles.ToList()).ToList()
            .ForEach(p =>
            {
                rids.AddRange(p);
            });
            var roles = await this._serviceProvider.GetRequiredService <IRoleRepository>().GetList(rids);

            //组装响应数据
            var accountInfos = Mapper.Map <List <AccountInfoBaseResponseDto> >(accounts);

            accountInfos.ForEach(ainfo =>
            {
                var account = accounts.FirstOrDefault(a => a.Id == ainfo.Id);
                ainfo.Roles = roles
                              .Where(r => r.IsNormal() && account.Roles.Contains(r.Id))
                              .Select(r => r.Name)
                              .ToList();
            });
            return(ResultPagedList <AccountInfoBaseResponseDto> .ReSuccess(accountInfos, accountsResult.TotalCount));
        }