Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var comments = new List<Comment>();
- // Validate input.
- if (linqComments == null)
- return comments;
- var rawComments = linqComments.OrderBy(a => a.id).ToList();
- // 1. Populate all comments in thread.
- foreach (var linqComment in rawComments.Where(a => a.ParentId == null))
- {
- // Get domain instance.
- Comment rootComment = GetDomainInstance(linqComment, commentaryThread);
- comments.Add(rootComment);
- //Throw children into that shit
- var children = rawComments.Where(a => a.ParentId == rootComment.Id).ToList().Select(a => GetDomainInstance(a, commentaryThread));
- foreach(var child in children)
- {
- child.ParentComment = rootComment;
- }
- comments.AddRange(children);
- }
- foreach(var comment in comments)
- {
- if(reportComments != null)
- {
- comment.CommentReports = new List<CommentReport>();
- var theseCommentReports = reportComments.Where(a => a.CommentId == comment.Id).ToList();
- foreach(var commentReport in theseCommentReports)
- {
- comment.CommentReports.Add(GetDomainInstance(commentReport, comment));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement