예제 #1
0
        public async Task <AdminPostIndexDto> GetAdminIndexAsync(
            AdminPostIndexFilter filter)
        {
            var postType = await _postTypeRepository
                           .GetBySlugAsync(filter.PostTypeSlug);

            if (postType == null)
            {
                throw new PostTypeNotFoundException();
            }

            var result = new AdminPostIndexDto {
                PostTypeSlug  = postType.Slug,
                PostTypeTitle = postType.Title
            };

            var query = _repository
                        .Query()
                        .Include(_ => _.Language)
                        .Include(_ => _.CreatorUser)
                        .Include(_ => _.ModifierUser)
                        .Include(_ => _.Category)
                        .Include(_ => _.PostTags)
                        .ThenInclude(_ => _.Tag)
                        .Where(_ => _.PostTypeId == postType.Id)
                        .Where(_ => !_.IsComponent);

            result.DataSource.TotalCount = await query.CountAsync();

            result.DataSource.PageIndex = filter.PageIndex;
            result.DataSource.PageSize  = filter.PageSize;

            query = query.SetFilter(filter)
                    .Skip(filter.StartIndex)
                    .Take(filter.PageSize);

            result.DataSource.Items = await query
                                      .Select(_ => _.Adapt <AdminPostIndexItemDto>())
                                      .ToListAsync();

            return(await Task.FromResult(result));
        }
예제 #2
0
        //public async Task<PostTypeResultDto> GetBySlugAsync(string slug) => await
        //    Task.FromResult(_repo.GetBySlugAsync(slug)
        //        .Adapt<PostTypeResultDto>()
        //    );


        public async Task <PostTypeResultDto> GetBySlugAsync(string slug)
        {
            var result = await _repo.GetBySlugAsync(slug);

            return(result.Adapt <PostTypeResultDto>());
        }