Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1.             var comments = new List<Comment>();
  2.  
  3.             // Validate input.
  4.             if (linqComments == null)
  5.                 return comments;
  6.  
  7.             var rawComments = linqComments.OrderBy(a => a.id).ToList();
  8.  
  9.             // 1. Populate all comments in thread.
  10.             foreach (var linqComment in rawComments.Where(a => a.ParentId == null))
  11.             {
  12.                 // Get domain instance.
  13.                 Comment rootComment = GetDomainInstance(linqComment, commentaryThread);
  14.                 comments.Add(rootComment);
  15.  
  16.                 //Throw children into that shit
  17.                 var children = rawComments.Where(a => a.ParentId == rootComment.Id).ToList().Select(a => GetDomainInstance(a, commentaryThread));
  18.                 foreach(var child in children)
  19.                 {
  20.                     child.ParentComment = rootComment;
  21.                 }
  22.                 comments.AddRange(children);
  23.             }
  24.  
  25.             foreach(var comment in comments)
  26.             {
  27.                 if(reportComments != null)
  28.                 {
  29.                     comment.CommentReports = new List<CommentReport>();
  30.                     var theseCommentReports = reportComments.Where(a => a.CommentId == comment.Id).ToList();
  31.                     foreach(var commentReport in theseCommentReports)
  32.                     {
  33.                         comment.CommentReports.Add(GetDomainInstance(commentReport, comment));
  34.                     }
  35.                 }
  36.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement