public List <CommentTreeDto> GetCommentTrees(List <CommentDto> dtoList, int parentId = 0)
        {
            var treeList = new List <CommentTreeDto>();
            var rootList = dtoList.Where(x => x.ParentId == parentId);

            foreach (var item in rootList)
            {
                var tree = new CommentTreeDto();
                _util.GetDtoTree(item, tree, dtoList);
                treeList.Add(tree);
            }
            return(treeList);
        }
예제 #2
0
        public List <CommentTreeDto> GetAllCommentByTree(List <CommentDto> dtoList)
        {
            var treeList = new List <CommentTreeDto>();
            var rootList = dtoList.Where(x => x.ParentId == 0);

            foreach (var item in rootList)
            {
                var tree = new CommentTreeDto();
                GetTree(item, tree, dtoList);
                treeList.Add(tree);
            }
            return(treeList);
        }
예제 #3
0
        private void GetTree(CommentDto dto, CommentTreeDto tree, List <CommentDto> list)
        {
            if (null == dto)
            {
                return;
            }
            tree = _mapper.Map(dto, tree);
            var childs = list.Where(x => x.ParentId == dto.Id).ToList();

            foreach (var child in childs)
            {
                var node = new CommentTreeDto();
                tree.Childrens.Add(node);
                GetTree(child, node, list);
            }
        }