diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs
index 54fce823..0beb7332 100644
--- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs
+++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs
@@ -37,6 +37,12 @@ namespace RMuseum.Models.Ganjoor.ViewModels
///
public string PublishStatus { get; set; }
+
+ ///
+ /// in reply to
+ ///
+ public int? InReplyToId { get; set; }
+
///
/// replies
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index e802e112..204ad5ca 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -4213,6 +4213,11 @@
status
+
+
+ in reply to
+
+
replies
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index 9354ae2d..dd5c081f 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -427,24 +427,12 @@ namespace RMuseum.Services.Implementation
{
try
{
- return new RServiceResult(await _GetPoemComments(poemId, userId, null));
- }
- catch (Exception exp)
- {
- return new RServiceResult(null, exp.ToString());
- }
- }
-
- private async Task _GetPoemComments(int poemId, Guid userId, int? inReplyToId)
- {
- var source =
+ var source =
from comment in _context.GanjoorComments.Include(c => c.User)
where
(comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId))
&&
comment.PoemId == poemId
- &&
- comment.InReplyToId == inReplyToId
orderby comment.CommentDate
select new GanjoorCommentSummaryViewModel()
{
@@ -453,15 +441,34 @@ namespace RMuseum.Services.Implementation
AuthorUrl = comment.AuthorUrl,
CommentDate = comment.CommentDate,
HtmlComment = comment.HtmlComment,
- PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : ""
+ PublishStatus = comment.Status == PublishStatus.Awaiting ? "در انتظار تأیید" : "",
+ InReplyToId = comment.InReplyToId,
};
- var comments = await source.ToArrayAsync();
- foreach(var comment in comments)
- {
- comment.Replies = await _GetPoemComments(poemId, userId, comment.Id);
+ GanjoorCommentSummaryViewModel[] allComments = await source.ToArrayAsync();
+
+ GanjoorCommentSummaryViewModel[] rootComments = allComments.Where(c => c.InReplyToId == null).ToArray();
+
+ foreach(GanjoorCommentSummaryViewModel comment in rootComments)
+ {
+ _FindReplies(comment, allComments);
+ }
+
+ return new RServiceResult(rootComments);
+ }
+ catch (Exception exp)
+ {
+ return new RServiceResult(null, exp.ToString());
+ }
+ }
+
+ private void _FindReplies(GanjoorCommentSummaryViewModel comment, GanjoorCommentSummaryViewModel[] allComments)
+ {
+ comment.Replies = allComments.Where(c => c.InReplyToId == comment.Id).ToArray();
+ foreach(GanjoorCommentSummaryViewModel reply in comment.Replies)
+ {
+ _FindReplies(reply, allComments);
}
- return comments;
}