Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). 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>
160 lines
5.9 KiB
C#
160 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using DivanRazor.Pages;
|
|
using DivanRazor.Utils;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Divan;
|
|
|
|
namespace DivanRazor.Areas.User.Pages
|
|
{
|
|
/// <summary>
|
|
/// contributor-facing form for suggesting an edit to an already-approved DivanRelatedPerson.
|
|
/// Any logged-in user may submit here (same bar as suggesting a poem correction); nothing is
|
|
/// changed until a moderator approves it via Admin/ReviewPersonEdits. Reachable both from a
|
|
/// person's PersonWindow.open() modal and from the poem-correction moderation page
|
|
/// (ReviewEdits.cshtml, when a correction links to an existing person).
|
|
/// </summary>
|
|
public class SuggestPersonEditModel : LoginPartialEnabledPageModel
|
|
{
|
|
public SuggestPersonEditModel(HttpClient httpClient, IConfiguration configuration) : base(httpClient, configuration)
|
|
{
|
|
}
|
|
|
|
public string LastError { get; set; }
|
|
|
|
public string LastResult { get; set; }
|
|
|
|
public DivanRelatedPerson Person { get; set; }
|
|
|
|
[BindProperty]
|
|
public DivanPersonEditSuggestion Suggestion { get; set; }
|
|
|
|
public List<DivanGeoLocation> Locations { get; set; }
|
|
|
|
private async Task ReadLocationsAsync()
|
|
{
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/locations");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = await ReadErrorMessageAsync(response);
|
|
return;
|
|
}
|
|
|
|
Locations = new List<DivanGeoLocation>
|
|
{
|
|
new DivanGeoLocation() { Id = 0, Latitude = 0, Longitude = 0, Name = "" }
|
|
};
|
|
Locations.AddRange(JsonConvert.DeserializeObject<DivanGeoLocation[]>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
|
|
private async Task<bool> PreparePersonAsync(int id)
|
|
{
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/people/{id}");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = await ReadErrorMessageAsync(response);
|
|
return false;
|
|
}
|
|
|
|
Person = JsonConvert.DeserializeObject<DivanRelatedPerson>(await response.Content.ReadAsStringAsync());
|
|
if (Person == null)
|
|
{
|
|
LastError = "نامبردهای با این کد پیدا نشد.";
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void FillSuggestionFromCurrentPerson()
|
|
{
|
|
// the form is pre-filled with the person's CURRENT values, so submitting without
|
|
// changing anything is a no-op suggestion (harmless, just not useful) rather than
|
|
// accidentally blanking fields the contributor didn't mean to touch
|
|
Suggestion = new DivanPersonEditSuggestion()
|
|
{
|
|
PersonId = Person.Id,
|
|
SuggestedName = Person.Name,
|
|
SuggestedDescription = Person.Description,
|
|
SuggestedWikiUrl = Person.WikiUrl,
|
|
SuggestedBirthYearInLHijri = Person.BirthYearInLHijri,
|
|
SuggestedDeathYearInLHijri = Person.DeathYearInLHijri,
|
|
SuggestedValidBirthDate = Person.ValidBirthDate,
|
|
SuggestedValidDeathDate = Person.ValidDeathDate,
|
|
SuggestedBirthLocationId = Person.BirthLocationId,
|
|
SuggestedDeathLocationId = Person.DeathLocationId,
|
|
SuggestedFamilyTreeCaption = Person.FamilyTreeCaption,
|
|
SuggestedImportance = Person.Importance,
|
|
SuggestedGender = Person.Gender,
|
|
};
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync(int id)
|
|
{
|
|
InitializeCommonPageState();
|
|
|
|
if (!LoggedIn)
|
|
{
|
|
return Redirect($"/login?redirect={Uri.EscapeDataString(Request.Path + Request.QueryString)}");
|
|
}
|
|
|
|
await ReadLocationsAsync();
|
|
|
|
if (!await PreparePersonAsync(id))
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
FillSuggestionFromCurrentPerson();
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostSuggestEditAsync(int id)
|
|
{
|
|
InitializeCommonPageState();
|
|
|
|
if (!LoggedIn)
|
|
{
|
|
return Redirect($"/login?redirect={Uri.EscapeDataString(Request.Path + Request.QueryString)}");
|
|
}
|
|
|
|
LastResult = "";
|
|
|
|
await ReadLocationsAsync();
|
|
|
|
if (!await PreparePersonAsync(id))
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
await DivanSessionChecker.PrepareClient(secureClient, Request, Response);
|
|
|
|
HttpResponseMessage response = await secureClient.PostAsync(
|
|
$"{APIRoot.Url}/api/people/{id}/editsuggestion",
|
|
new StringContent(JsonConvert.SerializeObject(Suggestion), Encoding.UTF8, "application/json"));
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastResult = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
FillSuggestionFromCurrentPerson();
|
|
return Page();
|
|
}
|
|
|
|
LastResult = $"پیشنهاد ویرایش شما ثبت شد و پس از بررسی توسط مدیران اعمال خواهد شد. <a role=\"button\" href=\"javascript:void(0)\" onclick=\"PersonWindow.open({id})\" class=\"actionlink\">مشاهدهٔ اطلاعات این نامبرده</a>";
|
|
|
|
FillSuggestionFromCurrentPerson();
|
|
|
|
return Page();
|
|
}
|
|
}
|
|
}
|
|
}
|