diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 2d2f42e9..92d12eaa 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -12515,6 +12515,21 @@
+
+
+ reorder poem recitations by user upvotes + being elder score
+
+
+
+
+
+
+ up vote a recitation
+
+
+
+
+
Upload Enabled (temporary switch off/on for upload)
diff --git a/RMuseum/Services/Implementation/RecitationService.cs b/RMuseum/Services/Implementation/RecitationService.cs
index 58c68252..69c30be9 100644
--- a/RMuseum/Services/Implementation/RecitationService.cs
+++ b/RMuseum/Services/Implementation/RecitationService.cs
@@ -1869,6 +1869,49 @@ namespace RMuseum.Services.Implementationa
}
}
+ ///
+ /// reorder poem recitations by user upvotes + being elder score
+ ///
+ ///
+ ///
+ public async Task> ReOrderPoemRecitationsBasedOnUpVotesAndHistory(int poemId)
+ {
+ try
+ {
+ var recitations =
+ await _context.Recitations
+ .Where(r => r.ReviewStatus == AudioReviewStatus.Approved && r.GanjoorPostId == poemId)
+ .OrderByDescending(r => r.Id) //this causes the oldest recirations to become the first one
+ .ToListAsync();
+
+ for (var i = 0; i< recitations.Count; i++)
+ {
+ var recitation = recitations[i];
+ //audio order is used as a temporary variable in the following line and soon is get replaced by computed value
+ recitation.AudioOrder =
+ recitations.Count - 1 - i +
+ await _context.RecitationUserUpVotes.AsNoTracking().Where(r => r.RecitationId == recitation.Id)
+ .CountAsync(); //this way oldest recitations have an advantage which could be beaten by user ranks over time
+ }
+
+ recitations.Sort((a, b) => a.AudioOrder.CompareTo(b.AudioOrder));
+ for (var i = 0; i < recitations.Count; i++)
+ {
+ recitations[i].AudioOrder = i + 1;
+ _context.Update(recitations[i]);
+ }
+
+ await _context.SaveChangesAsync();
+
+
+ return new RServiceResult(true);
+ }
+ catch (Exception exp)
+ {
+ return new RServiceResult(false, exp.ToString());
+ }
+ }
+
///
/// up vote a recitation
///
@@ -1908,7 +1951,7 @@ namespace RMuseum.Services.Implementationa
_context.RecitationUserUpVotes.Add(vote);
await _context.SaveChangesAsync();
- //TODO compute new order for poem recitations here
+ await ReOrderPoemRecitationsBasedOnUpVotesAndHistory(recitation.GanjoorPostId);
return new RServiceResult(true);