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."); } } } }
public void Publish(Guid articleId) { Article article = _repository.Get(articleId); ICategoryDomainService categoryDomainService = _container.Resolve <ICategoryDomainService>(); Category category = categoryDomainService.Get(article.CategoryId); if (category.IsPublished) { if (article.Status != ArticleStatus.AUDITED) { throw new Exception("Article needs to be audited first."); } article.Status = ArticleStatus.PUBLISHED; } else { throw new Exception("You can only publish article below the public category."); } }
public ArticleIncludeOutput Get(int id, string include) { var entity = _articleDomainService.Get(id); var result = new ArticleIncludeOutput() { Article = Mapper.Map <ArticleDto>(entity) }; foreach (string resourceName in include.AnalyzeInclude()) { switch (resourceName) { case "tags": result.Tags = _articleTagDomainService.GetTags(id).ProjectTo <TagDto>().ToList(); continue; case "category": result.Category = _categoryDomainService.Get(entity.CategoryId).MapTo <CategoryDto>(); continue; } } return(result); }
public CategoryDto Get(Guid id) { Category category = _domainService.Get(id); return(Mapper.Map <CategoryDto>(category)); }