예제 #1
0
        public async Task <(IList <Role> Roles, int TotalCount)> GetList(RoleListPagedRequestDto requestDto)
        {
            var queryable = _dbContext.Roles
                            .Where(w => w.Id > 0);

            if (!string.IsNullOrEmpty(requestDto.Vague))
            {
                queryable = queryable
                            .Where(w => w.Id.ToString() == requestDto.Vague ||
                                   EF.Functions.Like(w.Name, "%" + requestDto.Vague + "%"));
            }
            if (requestDto.Enable == 1)
            {
                queryable = queryable.Where(w => w.Enable == true);
            }
            if (requestDto.Enable == 0)
            {
                queryable = queryable.Where(w => w.Enable == false);
            }

            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 <Role> >(list), result.Count());
        }
예제 #2
0
        public async Task <ResultPagedList <RoleInfoBaseResponseDto> > GetList([FromBody] RoleListPagedRequestDto dto)
        {
            //验证请求数据合法性
            var result = dto.Valid();

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

            //获取角色
            var roelResult = await this._roleRepository.GetList(dto);

            var roles = Mapper.Map <IList <RoleInfoBaseResponseDto> >(roelResult.Roles);

            return(ResultPagedList <RoleInfoBaseResponseDto> .ReSuccess(roles, roelResult.TotalCount));
        }
예제 #3
0
        public async Task <(IList <Role> Roles, int TotalCount)> GetList(RoleListPagedRequestDto requestDto)
        {
            var list = await _roleCache.GetAsync(_cacheKey, _duration, async() => await _repository.GetList(), _logger);

            var queryable = list.Where(w => w.Id > 0);

            if (!string.IsNullOrEmpty(requestDto.Vague))
            {
                queryable = queryable
                            .Where(w => w.Id.ToString() == requestDto.Vague ||
                                   w.Name.Contains(requestDto.Vague));
            }
            if (requestDto.Enable == 1)
            {
                queryable = queryable.Where(w => w.Enable == true);
            }
            if (requestDto.Enable == 0)
            {
                queryable = queryable.Where(w => w.Enable == false);
            }

            return(queryable.Skip((requestDto.SkipPage - 1) * requestDto.PagedCount).Take(requestDto.PagedCount).ToList(), queryable.Count());
        }