private GetCommentsModel GenerateGetCommentsModel(int postId) { var commentaryService = new CommentaryService(); var comments = commentaryService.SearchCommentsByIdPost(new SearchCommentsByIdPostRequest() { IdPost = postId }).Comments; var commentsResult = new GetCommentsModel(); commentsResult.Comments = new List <CommentaryModel>(); foreach (var commentary in comments) { if (!commentary.IdUpperComment.HasValue) { var commentaryToAdd = TheModelFactory.CreateCommentaryModel(commentary); commentaryToAdd.Answers = new List <AnswerModel>(); foreach (var answer in comments) { if (answer.IdUpperComment.HasValue) { if (answer.IdUpperComment == commentary.Id) { var answerToAdd = TheModelFactory.CreateAnswerModel(answer); commentaryToAdd.Answers.Add(answerToAdd); } } } commentsResult.Comments.Add(commentaryToAdd); } } return(commentsResult); }