divan/DiwanRazor/Pages/Recitations/RecitationsOrder.cshtml.cs
Anas Rashid 020b010483 Urdu public pages, batch 2 (#2): auth, errors, map, FAQ, similar poems, people pages, page titles
- translate remaining public views and page-model strings (titles, messages, relation names)
- Urdu stopword list for word-frequency stats (replaces Persian list)
- error pages: drop list of alternative Ganjoor services

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 00:22:09 +02:00

86 lines
2.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using RMuseum.Models.DiwanAudio.ViewModels;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace DiwanRazor.Pages
{
public class RecitationsOrderModel : PageModel
{
/// <summary>
/// HttpClient instance
/// </summary>
private readonly HttpClient _httpClient;
/// <summary>
/// configration file reader (appsettings.json)
/// </summary>
private readonly IConfiguration Configuration;
/// <summary>
/// constructor
/// </summary>
/// <param name="httpClient"></param>
/// <param name="configuration"></param>
public RecitationsOrderModel(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient;
Configuration = configuration;
}
/// <summary>
/// Last Error
/// </summary>
public string LastError { get; set; }
public RecitationOrderingViewModel[] Scores { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (bool.Parse(Configuration["MaintenanceMode"]))
{
return StatusCode(503);
}
LastError = "";
if (!string.IsNullOrEmpty(Request.Query["p"]))
{
var poemId = int.Parse(Request.Query["p"]);
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/votes/{poemId}/scores");
if (!response.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
}
else
{
Scores = JsonConvert.DeserializeObject<RecitationOrderingViewModel[]>(await response.Content.ReadAsStringAsync());
if(Scores.Length > 0)
{
response = await _httpClient.GetAsync($"{APIRoot.Url}/api/diwan/poem/{poemId}/recitations");
if(!response.IsSuccessStatusCode)
{
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
}
var recitations = JsonConvert.DeserializeObject<PublicRecitationViewModel[]>(await response.Content.ReadAsStringAsync());
foreach (var score in Scores)
{
score.Recitation = recitations.Where(r => r.Id == score.RecitationId).Single();
}
}
}
}
else
{
LastError = "کوئی شعر منتخب نہیں.";
}
return Page();
}
}
}