Ejemplo n.º 1
0
        public void DeleteAndAdoptChildren(Guid id, Guid targetId)
        {
            Category category = _repository.Get(id);

            var childrenCategory = _repository.List(new CategoryFilterSpecification(id));

            foreach (var child in childrenCategory)
            {
                child.ParentId = targetId;
                _repository.Update(child);
            }

            // maybe have performance issue for cascading delete
            IArticleDomainService articleDomainService = _container.Resolve <IArticleDomainService>();

            var articles = articleDomainService.List(new ArticleFilterSpecification(id));

            foreach (var article in articles)
            {
                articleDomainService.Update(new ArticleUpdateBo()
                {
                    CategoryId = article.CategoryId
                });
            }

            _repository.Delete(category);
        }
Ejemplo n.º 2
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))));
        }
Ejemplo n.º 3
0
        public void Delete(Guid id)
        {
            Category category = _repository.Get(id);

            var children = _repository.List(new CategoryFilterSpecification(id));

            foreach (var child in children)
            {
                Delete(child.Id);
            }

            IArticleDomainService articleDomainService = _container.Resolve <IArticleDomainService>();

            var articles = articleDomainService.List(new ArticleFilterSpecification(id, null, null));

            foreach (var article in articles)
            {
                articleDomainService.Delete(article.Id);
            }
            _repository.Delete(category);
        }