Пример #1
0
        public void NestsComments()
        {
            var source = new[]
            {
                new CommentDto {
                    Id = 1
                },
                new CommentDto {
                    Id = 2
                },
                new CommentDto {
                    Id = 3, ReplyToId = 1
                },
                new CommentDto {
                    Id = 4, ReplyToId = 2
                },
                new CommentDto {
                    Id = 5, ReplyToId = 3
                }
            };

            var actual = CommentGraph.Nest(source).ToArray();

            Assert.Equal(2, actual.Length);
        }
        public async Task <IActionResult> Get(int linkId, CancellationToken ct)
        {
            var data = await _context.Comments
                       .Where(c => c.LinkId == linkId)
                       .ToListAsync(cancellationToken: ct)
                       .ConfigureAwait(false);

            if (data.Count == 0)
            {
                return(Ok(Enumerable.Empty <CommentDto>()));
            }

            var comments = _mapper.Map <List <CommentDto> >(data);

            return(Ok(CommentGraph.Nest(comments)));
        }