divan/DivanRazor/Pages/FAQ.cshtml.cs
Anas Rashid e3e3819c78 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

85 lines
2.9 KiB
C#

using DivanRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OutputCaching;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.FAQ;
using RMuseum.Models.Divan.ViewModels;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace DivanRazor.Pages
{
[OutputCache(PolicyName = "DivanPublicPage")]
public class FAQModel : LoginPartialEnabledPageModel
{
private readonly PoetCacheService _poetCache;
public string LastError { get; set; }
public List<DivanPoetViewModel> Poets { get; set; }
public List<FAQCategory> PinnedItemsCategories { get; set; }
public FAQItem Question { get; set; }
public async Task<IActionResult> OnGetAsync()
{
var maintenanceResult = TryGetMaintenanceModeResult();
if (maintenanceResult != null)
{
return maintenanceResult;
}
ViewData["Title"] = $"دیوان » عام سوالات";
InitializeCommonPageState();
var (poetsOk, poets, poetsError) = await _poetCache.GetPoetsAsync(EditorCacheBypass);
if (!poetsOk)
{
LastError = poetsError;
return Page();
}
Poets = poets;
if (!string.IsNullOrEmpty(Request.Query["id"]))
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/faq/{Request.Query["id"]}");
if (!response.IsSuccessStatusCode)
{
LastError = await ReadErrorMessageAsync(response);
if (string.IsNullOrEmpty(LastError))
{
LastError = $"سوال کی معلومات لانے میں خرابی - خرابی کا کوڈ = {response.StatusCode}";
}
return Page();
}
Question = JsonConvert.DeserializeObject<FAQItem>(await response.Content.ReadAsStringAsync());
ViewData["Title"] += $" » {Question.Question}";
}
else
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/faq/pinned");
if (!response.IsSuccessStatusCode)
{
LastError = await ReadErrorMessageAsync(response);
return Page();
}
PinnedItemsCategories = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<FAQCategory>>();
}
return Page();
}
/// <summary>
/// constructor
/// </summary>
public FAQModel(HttpClient httpClient, IConfiguration configuration, PoetCacheService poetCache) : base(httpClient, configuration)
{
_poetCache = poetCache;
}
}
}