#420 user SuggestQuoted page
This commit is contained in:
parent
282da2837c
commit
cf2c9849f1
@ -1,5 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
467
GanjooRazor/Areas/User/Pages/SuggestQuoted.cshtml
Normal file
467
GanjooRazor/Areas/User/Pages/SuggestQuoted.cshtml
Normal file
@ -0,0 +1,467 @@
|
||||
@page
|
||||
@model GanjooRazor.Areas.User.Pages.SuggestQuotedModel
|
||||
@using DNTPersianUtils.Core
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@{
|
||||
Layout = "_UserPanelLayout";
|
||||
ViewData["Title"] = "پیشنهاد مشق شعر";
|
||||
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>@Html.Raw(Model.LastMessage)</p>
|
||||
|
||||
@if (Model.GanjoorQuotedPoem != null && Model.Couplets != null)
|
||||
{
|
||||
<script>
|
||||
|
||||
function selectGanjoorPage() {
|
||||
document.getElementById('display-frame').style.display = 'none';
|
||||
document.getElementById('select-poem').style.display = 'block';
|
||||
document.getElementById('finalize-select').style.display = 'block';
|
||||
}
|
||||
|
||||
function finalizeSelectPage() {
|
||||
|
||||
document.getElementById('display-frame').style.display = 'block';
|
||||
document.getElementById('select-poem').style.display = 'none';
|
||||
document.getElementById('finalize-select').style.display = 'none';
|
||||
|
||||
const currentUrl = document.getElementById('select-poem').contentWindow.location.href;
|
||||
|
||||
var url = currentUrl.substring(currentUrl.indexOf('/', currentUrl.indexOf('//') + 2));
|
||||
|
||||
fetch('@(GanjooRazor.APIRoot.InternetUrl)/api/ganjoor/page?url=' + url)
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
alert(json.poem.id);
|
||||
document.getElementById('GanjoorQuotedPoem_RelatedPoemId').value = json.poem.id;
|
||||
document.getElementById('GanjoorQuotedPoem_RelatedPoetId').value = json.poem.category.poet.id;
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemPoetName').value = json.poem.category.poet.nickname;
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemPoetDeathYearInLHijri').value = json.poem.category.poet.deathYearInLHijri.toString();
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemPoetUrl').value = json.poem.category.poet.fullUrl;
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemPoetImage').value = json.poem.category.poet.imageUrl;
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemFullTitle').value = json.poem.fullTitle;
|
||||
document.getElementById('GanjoorQuotedPoem_CachedRelatedPoemFullUrl').value = json.poem.fullUrl;
|
||||
|
||||
var coupletIndices = [];
|
||||
var coupletTexts = [];
|
||||
|
||||
for (var i = 0; i < json.poem.verses.length; i++) {
|
||||
var verse = json.poem.verses[i];
|
||||
if (coupletIndices.indexOf(verse.coupletIndex) != -1) {
|
||||
coupletTexts[coupletIndices.indexOf(verse.coupletIndex)] += ' - ';
|
||||
coupletTexts[coupletIndices.indexOf(verse.coupletIndex)] += verse.text;
|
||||
}
|
||||
else {
|
||||
coupletIndices.push(verse.coupletIndex);
|
||||
coupletTexts.push(verse.text);
|
||||
}
|
||||
}
|
||||
|
||||
var x = document.getElementById("GanjoorQuotedPoem_RelatedCoupletIndex");
|
||||
x.length = 0;
|
||||
for (var i = 0; i < coupletIndices.length; i++) {
|
||||
var option = document.createElement("option");
|
||||
option.text = coupletTexts[i];
|
||||
option.value = coupletIndices[i];
|
||||
x.add(option);
|
||||
}
|
||||
|
||||
x.value = coupletIndices[0];
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deleteThisOne(id) {
|
||||
if (!confirm('آیا از حذف این مورد اطمینان دارید؟'))
|
||||
return;
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: '',
|
||||
data: {
|
||||
id: id
|
||||
},
|
||||
error: function (e) {
|
||||
if (e.responseText == null)
|
||||
alert(e);
|
||||
else
|
||||
alert(e.responseText);
|
||||
},
|
||||
success: function () {
|
||||
alert('انجام شد.');
|
||||
location.reload(true);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function reverseQuote(id) {
|
||||
if (!confirm('آیا از درج معکوس این مورد اطمینان دارید؟'))
|
||||
return;
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '?handler=GenerateReverse',
|
||||
data: {
|
||||
id: id
|
||||
},
|
||||
error: function (e) {
|
||||
if (e.responseText == null)
|
||||
alert(e);
|
||||
else
|
||||
alert(e.responseText);
|
||||
},
|
||||
success: function (e) {
|
||||
alert('انجام شد.');
|
||||
location.href = e;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
بیت مرجع از <a href="/?p=@Model.GanjoorQuotedPoem.PoemId">شعر</a>:
|
||||
<input type="hidden" asp-for="GanjoorQuotedPoem.Id" />
|
||||
<input type="hidden" asp-for="GanjoorQuotedPoem.PoemId" />
|
||||
<input type="hidden" asp-for="GanjoorQuotedPoem.PoetId" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<select asp-for="GanjoorQuotedPoem.CoupletIndex" style="width:100%">
|
||||
@foreach (var item in Model.Couplets)
|
||||
{
|
||||
<option value="@item.Item1">@($"{(item.Item1 + 1).ToPersianNumbers()} - {item.Item2}")</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مصرع اول مهم است:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CoupletVerse1ShouldBeEmphasized" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مصرع دوم مهم است:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CoupletVerse2ShouldBeEmphasized" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
شاعر مرجع:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.PoetId" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a onclick="finalizeSelectPage()" class="pagebutton" role="button" id="finalize-select" style="display:none">انتخاب کردم</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<iframe id="select-poem" src="/" height="600" style="display:none;width:100%;margin:auto"></iframe>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<a onclick="selectGanjoorPage()" class="pagebutton" role="button" id="display-frame">گزینش شعر مرتبط</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedPoemId" />
|
||||
</td>
|
||||
</tr>
|
||||
@if (Model.GanjoorQuotedPoem.RelatedPoemId != null)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/?p=@Model.GanjoorQuotedPoem.RelatedPoemId">مشاهدهٔ شعر مرتبط</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
بیت مرتبط:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<select asp-for="GanjoorQuotedPoem.RelatedCoupletIndex" style="width:100%;">
|
||||
@foreach (var item in Model.RelatedCouplets)
|
||||
{
|
||||
<option value="@item.Item1">@($"{(item.Item1 + 1).ToPersianNumbers()} - {item.Item2}")</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مصرع اول مرتبط (خارج از گنجور):
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedCoupletVerse1" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مصرع اول مهم است:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedCoupletVerse1ShouldBeEmphasized" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مصرع دوم مرتبط (خارج از گنجور):
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedCoupletVerse2" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
مصرع دوم مهم است:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedCoupletVerse2ShouldBeEmphasized" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
ترتیب:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.SortOrder" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
این شعر قدیمیتر از شعر مرتبط است:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.IsPriorToRelated" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
نمایش در فهرست اصلی:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.ChosenForMainList" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
مستقیماً ارتباط ندارد:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.IndirectQuotation" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
منتسب به هر دو شاعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.ClaimedByBothPoets" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
شاعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.RelatedPoetId" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemPoetName" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
سالمرگ شاعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemPoetDeathYearInLHijri" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
نشانی صفحهٔ شاعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemPoetUrl" style="direction:ltr" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
تصویر شاعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemPoetImage" style="direction:ltr" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
عنوان شعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemFullTitle" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
نشانی شعر:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.CachedRelatedPoemFullUrl" style="direction:ltr" size="65" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
یادداشت:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<textarea asp-for="GanjoorQuotedPoem.Note" rows="4" cols="80" class="editor"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
منتشر شده:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.Published" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
تعداد همسانها:
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input asp-for="GanjoorQuotedPoem.SamePoemsQuotedCount" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="submit" value="ذخیره" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td><hr /></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
@if (Model.ReverseId != null)
|
||||
{
|
||||
<a href="/Admin/SuggestQuoted/?p=@Model.GanjoorQuotedPoem.RelatedPoemId&id=@Model.ReverseId">نمایش معکوس</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a role="button" onclick="reverseQuote('@Model.GanjoorQuotedPoem.Id')" class="actionlink" title="درج معکوس">درج معکوس</a>
|
||||
}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td><hr /></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a role="button" onclick="deleteThisOne('@Model.GanjoorQuotedPoem.Id')" class="actionlink" title="حذف">حذف <i class="noindent-info-button delete-icon"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<h1>همهٔ مشقهای شعر</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td>شاعر</td>
|
||||
<td>۱</td>
|
||||
<td>۲</td>
|
||||
<td>۱</td>
|
||||
<td>۲</td>
|
||||
<td>منتشر شده</td>
|
||||
</tr>
|
||||
@foreach (var q in Model.AllPoemQuoteds)
|
||||
{
|
||||
<tr>
|
||||
<td><a href="/Admin/SuggestQuoted/?p=@q.PoemId&id=@q.Id">#</a> </td>
|
||||
<td>@q.CachedRelatedPoemPoetName</td>
|
||||
<td>@q.CoupletVerse1</td>
|
||||
<td>@q.CoupletVerse2</td>
|
||||
<td>@q.RelatedCoupletVerse1</td>
|
||||
<td>@q.RelatedCoupletVerse2</td>
|
||||
<td>@q.Published</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
|
||||
}
|
||||
413
GanjooRazor/Areas/User/Pages/SuggestQuoted.cshtml.cs
Normal file
413
GanjooRazor/Areas/User/Pages/SuggestQuoted.cshtml.cs
Normal file
@ -0,0 +1,413 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using GanjooRazor.Utils;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace GanjooRazor.Areas.User.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class SuggestQuotedModel : PageModel
|
||||
{
|
||||
public string LastMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HttpClient instance
|
||||
/// </summary>
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="httpClient"></param>
|
||||
public SuggestQuotedModel(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public GanjoorPoemCompleteViewModel Poem { get; set; }
|
||||
|
||||
public GanjoorPoemCompleteViewModel RelatedPoem { get; set; }
|
||||
|
||||
public Tuple<int, string>[] Couplets { get; set; }
|
||||
|
||||
public Tuple<int, string>[] RelatedCouplets { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public GanjoorQuotedPoemViewModel GanjoorQuotedPoem { get; set; }
|
||||
|
||||
public GanjoorQuotedPoemViewModel[] AllPoemQuoteds { get; set; }
|
||||
public Guid? ReverseId { get; set; }
|
||||
|
||||
|
||||
private Tuple<int, string>[] GetCouplets(GanjoorVerseViewModel[] verses)
|
||||
{
|
||||
int coupetIndex = -1;
|
||||
string coupletText = "";
|
||||
List<Tuple<int, string>> couplets = new List<Tuple<int, string>>();
|
||||
int verseIndex = 0;
|
||||
bool incompleteCouplet = false;
|
||||
while (verseIndex < verses.Length)
|
||||
{
|
||||
switch (verses[verseIndex].VersePosition)
|
||||
{
|
||||
case VersePosition.Comment:
|
||||
incompleteCouplet = false;
|
||||
if (!string.IsNullOrEmpty(coupletText))
|
||||
{
|
||||
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
|
||||
coupletText = "";
|
||||
}
|
||||
break;
|
||||
case VersePosition.Paragraph:
|
||||
case VersePosition.Single:
|
||||
incompleteCouplet = false;
|
||||
if (!string.IsNullOrEmpty(coupletText))
|
||||
{
|
||||
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
|
||||
coupletText = "";
|
||||
}
|
||||
coupetIndex++;
|
||||
couplets.Add(new Tuple<int, string>(coupetIndex, verses[verseIndex].Text));
|
||||
break;
|
||||
case VersePosition.Right:
|
||||
case VersePosition.CenteredVerse1:
|
||||
incompleteCouplet = false;
|
||||
if (!string.IsNullOrEmpty(coupletText))
|
||||
{
|
||||
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
|
||||
}
|
||||
coupetIndex++;
|
||||
coupletText = verses[verseIndex].Text;
|
||||
break;
|
||||
case VersePosition.Left:
|
||||
case VersePosition.CenteredVerse2:
|
||||
incompleteCouplet = true;
|
||||
coupletText += $" - {verses[verseIndex].Text}";
|
||||
break;
|
||||
}
|
||||
verseIndex++;
|
||||
}
|
||||
|
||||
|
||||
if (incompleteCouplet && !string.IsNullOrEmpty(coupletText))
|
||||
couplets.Add(new Tuple<int, string>(coupetIndex, coupletText));
|
||||
|
||||
return couplets.ToArray();
|
||||
}
|
||||
|
||||
private async Task<string> Prepare(int poemId, string id)
|
||||
{
|
||||
LastMessage = "";
|
||||
var poemQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}");
|
||||
if (!poemQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await poemQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
Poem = JObject.Parse(await poemQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPoemCompleteViewModel>();
|
||||
|
||||
Couplets = GetCouplets(Poem.Verses);
|
||||
RelatedCouplets = [];
|
||||
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
|
||||
var quoteQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/quoted/{id}");
|
||||
if (!quoteQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await quoteQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
GanjoorQuotedPoem = JObject.Parse(await quoteQuery.Content.ReadAsStringAsync()).ToObject<GanjoorQuotedPoemViewModel>();
|
||||
if (GanjoorQuotedPoem.RelatedPoemId != null)
|
||||
{
|
||||
var relPoemQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorQuotedPoem.RelatedPoemId}");
|
||||
if (!relPoemQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await relPoemQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
RelatedPoem = JObject.Parse(await relPoemQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPoemCompleteViewModel>();
|
||||
|
||||
RelatedCouplets = GetCouplets(RelatedPoem.Verses);
|
||||
|
||||
|
||||
var revQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorQuotedPoem.RelatedPoemId}/quoteds/{GanjoorQuotedPoem.PoemId}");
|
||||
if (!revQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await revQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
|
||||
var revs = JsonConvert.DeserializeObject<GanjoorQuotedPoemViewModel[]>(await revQuery.Content.ReadAsStringAsync());
|
||||
var rev = revs.Where(r => r.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex && r.RelatedCoupletIndex == GanjoorQuotedPoem.CoupletIndex).SingleOrDefault();
|
||||
if (rev != null)
|
||||
{
|
||||
ReverseId = rev.Id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GanjoorQuotedPoem = new GanjoorQuotedPoemViewModel()
|
||||
{
|
||||
PoemId = poemId,
|
||||
PoetId = Poem.Category.Poet.Id,
|
||||
RelatedPoetId = null,
|
||||
RelatedPoemId = null,
|
||||
IsPriorToRelated = false,
|
||||
ChosenForMainList = true,
|
||||
CachedRelatedPoemPoetDeathYearInLHijri = 0,
|
||||
CachedRelatedPoemPoetName = null,
|
||||
CachedRelatedPoemPoetUrl = null,
|
||||
CachedRelatedPoemPoetImage = null,
|
||||
CachedRelatedPoemFullTitle = null,
|
||||
CachedRelatedPoemFullUrl = null,
|
||||
SortOrder = 1000,
|
||||
Note = "",
|
||||
Published = false,
|
||||
ClaimedByBothPoets = false,
|
||||
IndirectQuotation = false,
|
||||
SamePoemsQuotedCount = 0,
|
||||
RelatedCoupletVerse1 = null,
|
||||
RelatedCoupletVerse1ShouldBeEmphasized = false,
|
||||
RelatedCoupletVerse2 = null,
|
||||
RelatedCoupletVerse2ShouldBeEmphasized = false,
|
||||
RelatedCoupletIndex = null,
|
||||
CoupletVerse1 = Poem.Verses[0].Text,
|
||||
CoupletVerse1ShouldBeEmphasized = false,
|
||||
CoupletVerse2 = Poem.Verses[1].Text,
|
||||
CoupletVerse2ShouldBeEmphasized = false,
|
||||
CoupletIndex = 0,
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
var allQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/quoteds");
|
||||
if (!allQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await allQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
AllPoemQuoteds = JsonConvert.DeserializeObject<GanjoorQuotedPoemViewModel[]>(await allQuery.Content.ReadAsStringAsync());
|
||||
return LastMessage;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
|
||||
return Redirect("/");
|
||||
|
||||
|
||||
|
||||
string poemIdString = Request.Query["p"];
|
||||
if (string.IsNullOrEmpty(poemIdString))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Request.Query["id"]))
|
||||
{
|
||||
var quoteQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/quoted/{Request.Query["id"]}");
|
||||
if (!quoteQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await quoteQuery.Content.ReadAsStringAsync());
|
||||
return Page();
|
||||
}
|
||||
GanjoorQuotedPoem = JObject.Parse(await quoteQuery.Content.ReadAsStringAsync()).ToObject<GanjoorQuotedPoemViewModel>();
|
||||
poemIdString = GanjoorQuotedPoem.PoemId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
LastMessage = "شناسهٔ شعر مشخص نیست.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await Prepare(int.Parse(poemIdString), Request.Query["id"]);
|
||||
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(GanjoorQuotedPoemViewModel GanjoorQuotedPoem)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Prepare(GanjoorQuotedPoem.PoemId, GanjoorQuotedPoem.Id == Guid.Empty ? null : GanjoorQuotedPoem.Id.ToString());
|
||||
GanjoorQuotedPoem.CoupletVerse1 = Poem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.CoupletIndex).Count() < 1 ? "" : Poem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.CoupletIndex).ToArray()[0].Text;
|
||||
GanjoorQuotedPoem.CoupletVerse2 = Poem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.CoupletIndex).Count() < 2 ? "" : Poem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.CoupletIndex).ToArray()[1].Text;
|
||||
if (GanjoorQuotedPoem.RelatedPoemId != null && RelatedPoem == null)
|
||||
{
|
||||
var relPoemQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{GanjoorQuotedPoem.RelatedPoemId}");
|
||||
if (!relPoemQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await relPoemQuery.Content.ReadAsStringAsync());
|
||||
return Page();
|
||||
}
|
||||
RelatedPoem = JObject.Parse(await relPoemQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPoemCompleteViewModel>();
|
||||
|
||||
RelatedCouplets = GetCouplets(RelatedPoem.Verses);
|
||||
}
|
||||
|
||||
if (GanjoorQuotedPoem.RelatedCoupletIndex != null)
|
||||
{
|
||||
GanjoorQuotedPoem.RelatedCoupletVerse1 = RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).Count() < 1 ? "" : RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).ToArray()[0].Text;
|
||||
GanjoorQuotedPoem.RelatedCoupletVerse2 = RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).Count() < 2 ? "" : RelatedPoem.Verses.Where(v => v.CoupletIndex == GanjoorQuotedPoem.RelatedCoupletIndex).ToArray()[1].Text;
|
||||
}
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var url = $"{APIRoot.Url}/api/ganjoor/quoted";
|
||||
var payload = new StringContent(JsonConvert.SerializeObject(GanjoorQuotedPoem), Encoding.UTF8, "application/json");
|
||||
bool newRecord = GanjoorQuotedPoem.Id == Guid.Empty;
|
||||
HttpResponseMessage response =
|
||||
newRecord ?
|
||||
await secureClient.PostAsync(url, payload) :
|
||||
await secureClient.PutAsync(url, payload);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newRecord)
|
||||
{
|
||||
GanjoorQuotedPoem = JObject.Parse(await response.Content.ReadAsStringAsync()).ToObject<GanjoorQuotedPoemViewModel>();
|
||||
}
|
||||
|
||||
LastMessage = $"انجام شد. <br /><a href=\"/Admin/SuggestQuoted/?p={GanjoorQuotedPoem.PoemId}&id={GanjoorQuotedPoem.Id}\">برگشت</a>";
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LastMessage = "لطفاً از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LastMessage = e.ToString();
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnDeleteAsync(string id)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/quoted?id={id}");
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BadRequestObjectResult("لطفاً از گنجور خارج و مجددا به آن وارد شوید.");
|
||||
}
|
||||
}
|
||||
return new JsonResult(true);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostGenerateReverseAsync(string id)
|
||||
{
|
||||
var quoteQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/quoted/{id}");
|
||||
if (!quoteQuery.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await quoteQuery.Content.ReadAsStringAsync()));
|
||||
}
|
||||
var quote = JObject.Parse(await quoteQuery.Content.ReadAsStringAsync()).ToObject<GanjoorQuotedPoemViewModel>();
|
||||
|
||||
var poemQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{quote.PoemId}");
|
||||
if (!poemQuery.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await poemQuery.Content.ReadAsStringAsync());
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await quoteQuery.Content.ReadAsStringAsync()));
|
||||
}
|
||||
Poem = JObject.Parse(await poemQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPoemCompleteViewModel>();
|
||||
|
||||
GanjoorQuotedPoemViewModel reverseRelation = new GanjoorQuotedPoemViewModel()
|
||||
{
|
||||
PoemId = (int)quote.RelatedPoemId,
|
||||
PoetId = (int)quote.RelatedPoetId,
|
||||
RelatedPoetId = quote.PoetId,
|
||||
RelatedPoemId = quote.PoemId,
|
||||
IsPriorToRelated = !quote.IsPriorToRelated,
|
||||
ChosenForMainList = true,
|
||||
CachedRelatedPoemPoetDeathYearInLHijri = Poem.Category.Poet.DeathYearInLHijri,
|
||||
CachedRelatedPoemPoetName = Poem.Category.Poet.Nickname,
|
||||
CachedRelatedPoemPoetUrl = Poem.Category.Poet.FullUrl,
|
||||
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{Poem.Category.Poet.FullUrl}.gif",
|
||||
CachedRelatedPoemFullTitle = Poem.FullTitle,
|
||||
CachedRelatedPoemFullUrl = Poem.FullUrl,
|
||||
SortOrder = 1000,
|
||||
Note = quote.Note,
|
||||
Published = false,
|
||||
RelatedCoupletVerse1 = quote.CoupletVerse1,
|
||||
RelatedCoupletVerse1ShouldBeEmphasized = quote.CoupletVerse1ShouldBeEmphasized,
|
||||
RelatedCoupletVerse2 = quote.CoupletVerse2,
|
||||
RelatedCoupletVerse2ShouldBeEmphasized = quote.CoupletVerse2ShouldBeEmphasized,
|
||||
RelatedCoupletIndex = quote.CoupletIndex,
|
||||
CoupletVerse1 = quote.RelatedCoupletVerse1,
|
||||
CoupletVerse1ShouldBeEmphasized = quote.RelatedCoupletVerse1ShouldBeEmphasized,
|
||||
CoupletVerse2 = quote.RelatedCoupletVerse2,
|
||||
CoupletVerse2ShouldBeEmphasized = quote.RelatedCoupletVerse2ShouldBeEmphasized,
|
||||
CoupletIndex = quote.RelatedCoupletIndex,
|
||||
ClaimedByBothPoets = quote.ClaimedByBothPoets,
|
||||
IndirectQuotation = quote.IndirectQuotation,
|
||||
SamePoemsQuotedCount = 1,
|
||||
|
||||
};
|
||||
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var url = $"{APIRoot.Url}/api/ganjoor/quoted";
|
||||
var payload = new StringContent(JsonConvert.SerializeObject(reverseRelation), Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response =
|
||||
|
||||
await secureClient.PostAsync(url, payload)
|
||||
;
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await quoteQuery.Content.ReadAsStringAsync()));
|
||||
}
|
||||
else
|
||||
{
|
||||
reverseRelation = JObject.Parse(await response.Content.ReadAsStringAsync()).ToObject<GanjoorQuotedPoemViewModel>();
|
||||
return new JsonResult($"/Admin/EditQuoted/?p={reverseRelation.PoemId}&id={reverseRelation.Id}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>("لطفاً از گنجور خارج و مجددا به آن وارد شوید."));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -644,9 +644,9 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@if(Model.CanEdit)
|
||||
@if(Model.LoggedIn)
|
||||
{
|
||||
<a href="/Admin/EditQuoted/?p=@Model.GanjoorPage.Id" class="pagebutton comments-link">پیشنهاد مشق شعر</a>
|
||||
<a href="/User/SuggestQuoted/?p=@Model.GanjoorPage.Id" class="pagebutton comments-link">پیشنهاد مشق شعر</a>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user