docs: #302 UI for transfering a category

This commit is contained in:
Hamid Reza Mohammadi 2022-03-29 08:26:16 +04:30
parent a6c38daeff
commit 53520d2976
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,39 @@
@page
@model GanjooRazor.Areas.Admin.Pages.CatTransModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_AdminLayout";
ViewData["Title"] = "انتقال بخش";
}
<h1>@ViewData["Title"]</h1>
@if (!string.IsNullOrEmpty(Model.LastMessage))
{
@Html.Raw(Model.LastMessage)
}
else
{
<table>
<tr>
<th>مبدأ</th>
<th>مقصد</th>
</tr>
@foreach (var poem in Model.Poems)
{
<tr>
<td>
<a href="@poem.SrcPoemFullUrl">@poem.SrcPoemFullTitle</a>
</td>
<td>
@if(!string.IsNullOrEmpty(poem.DestPoemFullUrl))
{
<a href="@poem.DestPoemFullUrl">@poem.DestPoemFullTitle</a>
}
</td>
</tr>
}
</table>
}

View File

@ -0,0 +1,71 @@
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
namespace GanjooRazor.Areas.Admin.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class CatTransModel : PageModel
{
/// <summary>
/// last message
/// </summary>
public string LastMessage { get; set; }
/// <summary>
/// poems
/// </summary>
public GanjoorDuplicateViewModel[] Poems { get; set; }
private async Task<bool> _GetCatDuplicatesAsync()
{
if (string.IsNullOrEmpty(Request.Query["id"]))
{
LastMessage = "شناسهٔ بخش مشخص نیست.";
return false;
}
var id = Request.Query["id"];
using (HttpClient secureClient = new HttpClient())
{
if(await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/duplicates/{id}");
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return false;
}
else
{
Poems = JsonConvert.DeserializeObject<GanjoorDuplicateViewModel[]>(await response.Content.ReadAsStringAsync());
}
}
else
{
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
return false;
}
}
return true;
}
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
await _GetCatDuplicatesAsync();
return Page();
}
}
}

View File

@ -505,6 +505,8 @@
</tr>
</table>
<p><a href="/Admin/CatTrans?id=@Model.Cat.Cat.Id">انتقال بخش</a></p>