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); }
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); }
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); } }