示例#1
0
        private void HandleInclude(ArticleWithIncludeDto dto, string include)
        {
            if (!string.IsNullOrEmpty(include))
            {
                var entityIncludes = include.AnalyzeInclude();
                foreach (var entity in entityIncludes)
                {
                    switch (entity)
                    {
                    case "category":
                        dto.Category = Mapper.Map <CategoryRefDto>(_categoryDomainService.Get(dto.CategoryId));
                        break;

                    case "author":
                        dto.Author = Mapper.Map <AgentRefDto>(_agentDomainService.Get(dto.AuthorId));
                        break;

                    case "tags":
                        dto.Tags = dto.TagIds.Select(id => Mapper.Map <TagRefDto>(_tagDomainService.Get(id)));
                        break;

                    default:
                        throw new Exception("Invalid include parameters.");
                    }
                }
            }
        }
示例#2
0
        public ArticleWithIncludeDto Get(Guid id, string include)
        {
            Article article = _articleDomainService.Get(id);

            ArticleWithIncludeDto dto = Mapper.Map <ArticleWithIncludeDto>(article);

            HandleInclude(dto, include);

            return(dto);
        }
示例#3
0
        public PagedListDto <ArticleWithIncludeDto> GetList(ArticleQueryDto dto, string include, Paging paging)
        {
            var spec  = new ArticleFilterSpecification(dto.CategoryId, dto.TagId, dto.Keywords);
            int count = _articleDomainService.Count(spec);

            spec.ApplyPaging(paging);
            var list = _articleDomainService.List(spec);

            var listIncludes = list.Select(e =>
            {
                ArticleWithIncludeDto toDto = Mapper.Map <ArticleWithIncludeDto>(e);
                HandleInclude(toDto, include);
                return(toDto);
            });

            return(new PagedListDto <ArticleWithIncludeDto>(count, list.Select(e => Mapper.Map <ArticleWithIncludeDto>(e))));
        }