#264 getting list of upvoted reciations

This commit is contained in:
Hamid Reza Mohammadi 2021-12-21 19:45:10 +03:30
parent c5bb6a1612
commit d439337484
3 changed files with 48 additions and 4 deletions

View File

@ -204,9 +204,6 @@
</script>
@if (!string.IsNullOrEmpty(ViewData["GoogleAnalyticsCode"].ToString()))
{
<script>
@ -223,6 +220,16 @@
</script>
}
@if(Model.LoggedIn && Model.IsPoemPage)
{
if(Model.GanjoorPage.Poem.Recitations.Length > 0)
{
<script>
MarkUserUpvotedRecitations(@Model.GanjoorPage.Id);
</script>
}
}
</body>
</html>

View File

@ -837,6 +837,24 @@ namespace GanjooRazor.Pages
return new OkObjectResult(false);
}
public async Task<IActionResult> OnGetGetUserUpvotedRecitationsAsync(int poemId)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/recitations/upvotes");
if (!response.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
var res = JsonConvert.DeserializeObject<RecitationUserUpVoteViewModel[]>(await response.Content.ReadAsStringAsync());
return new OkObjectResult(res);
}
}
return new OkObjectResult("کاربر وارد سیستم نشده است یا مشکل دیگری دارد.");
}
public async Task<ActionResult> OnPostSwitchRecitationUpVoteAsync(int id)
{
using (HttpClient secureClient = new HttpClient())

View File

@ -862,4 +862,23 @@ function switchRecitationVote(recitationId) {
alert(e.responseText);
},
});
}
}
function MarkUserUpvotedRecitations(poemId) {
setTimeout(function () {
$.ajax({
type: "GET",
url: '?Handler=GetUserUpvotedRecitations&poemId=' + String(poemId),
error: function (err) {
console.log(err);
},
success: function (result) {
for (var i = 0; i < result.length; i++) {
if (result[i].upVote) {
document.getElementById('recitaion-' + String(result[i].id)).classList.add('recitation-vote');
}
}
},
});
}, 1);
}