예제 #1
0
        public async Task <IActionResult> Query([FromQuery] TopicRequestCondition Request = null)
        {
            IPagedList <BZTopicModel> pagedList = null;
            var query = Request.CreateQueryExpression <BZTopicModel, TopicRequestCondition>();

            query     = query.And(p => p.Status == 0);
            pagedList = await _bZTopicRepository.GetPagedListAsync(query, o => o.OrderBy(p => p.Id), null, Request.PageIndex - 1, Request.PageSize);

            if (pagedList != null && pagedList.Items.Any())
            {
                var pagedatas = pagedList.From(res => _mapper.Map <List <PersonalTopicDisplayDto> >(res));

                var users = await _cacheService.GetUsersAsync(p => pagedList.Items.Select(d => d.CreatorId).Contains(p.Id));

                foreach (PersonalTopicDisplayDto topic in pagedatas.Items)
                {
                    var user = users.FirstOrDefault(p => p.Id == topic.CreatorId);
                    if (user != null)
                    {
                        topic.UserName = user?.UserName;
                        topic.Avator   = user?.Avator;
                        topic.NickName = user?.NickName;
                    }
                }
                if (pagedatas is null || pagedatas.TotalCount == 0)
                {
                    return(NoContent());
                }
                return(Ok(pagedatas));
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <ActionResult <IPagedList <TopicDisplayDto> > > Query([FromQuery] TopicRequestCondition Request = null)
        {
            IPagedList <BZTopicModel> pagedList = null;
            var query = Request.CreateQueryExpression <BZTopicModel, TopicRequestCondition>();

            if (!string.IsNullOrWhiteSpace(Request.UserName))
            {
                var Users = await _cacheService.GetUsersAsync(p =>
                                                              p.UserName.Contains(Request.UserName) ||
                                                              p.NickName.Contains(Request.UserName));

                if (Users != null)
                {
                    query = query.And(p => Users.Select(x => x.Id).Contains(p.CreatorId));
                }
                else
                {
                    return(NoContent());
                }
            }
            pagedList = await _bZTopicRepository.GetPagedListAsync(query, o => o.OrderBy(p => p.Id), null, Request.PageIndex - 1, Request.PageSize);

            if (pagedList.Items.Any())
            {
                var pagedatas = pagedList.From(result => _mapper.Map <List <TopicDisplayDto> >(result));
                var users     = await _cacheService.GetUsersAsync(p => pagedList.Items.Select(d => d.CreatorId).Contains(p.Id));

                foreach (TopicDisplayDto topic in pagedatas.Items)
                {
                    topic.UserName = users.FirstOrDefault(p => p.Id == topic.CreatorId)?.UserName;
                    if (!string.IsNullOrWhiteSpace(topic.RoleId))
                    {
                        topic.RoleName = roleManager.Roles.FirstOrDefault(p => p.Id == topic.RoleId)?.Name;
                    }
                }
                return(Ok(pagedatas));
            }
            return(NoContent());
        }