divan/DiwanRazor/Pages/FAQ.cshtml.cs
Anas Rashid e8f2306422 Rename Ganjoor -> Diwan throughout the code
Projects (GanjooRazor -> DiwanRazor, GanjoorService.sln -> DiwanService.sln), files,
folders, classes, namespaces, settings, API routes (/api/diwan) and DB tables (Diwan*).
External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed
consistently (no pending model changes); requires a fresh database.
Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 23:49:01 +02:00

85 lines
2.9 KiB
C#

using DiwanRazor.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.Diwan.ViewModels;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace DiwanRazor.Pages
{
[OutputCache(PolicyName = "DiwanPublicPage")]
public class FAQModel : LoginPartialEnabledPageModel
{
private readonly PoetCacheService _poetCache;
public string LastError { get; set; }
public List<DiwanPoetViewModel> 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;
}
}
}