#203 edit language

This commit is contained in:
Hamid Reza Mohammadi 2021-09-14 19:56:34 +04:30
parent 7aa3524fc8
commit 9bd85be57f
3 changed files with 146 additions and 1 deletions

View File

@ -0,0 +1,71 @@
@page
@model GanjooRazor.Areas.User.Pages.LanguageEditModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
ViewData["Title"] = "ویرایش زبان یا نویسش";
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
}
<h1>@ViewData["Title"]</h1>
@if (!string.IsNullOrEmpty(Model.LastMessage))
{
<p>
@Model.LastMessage
</p>
}
else
{
<form method="post">
<table>
<tr>
<td>
نام:
</td>
<td>
<input type="hidden" asp-for="Language.Id" />
<input asp-for="Language.Name" />
</td>
</tr>
<tr>
<td>
کد:
</td>
<td>
<input style="direction:ltr" asp-for="Language.Code" />
</td>
</tr>
<tr>
<td>
نام بومی زبان:
</td>
<td>
<input style="direction:ltr" asp-for="Language.NativeName" />
</td>
</tr>
<tr>
<td>
راست به چپ:
</td>
<td>
<input type="checkbox" asp-for="Language.RightToLeft" />
</td>
</tr>
<tr>
<td>
شرح:
</td>
<td>
<input asp-for="Language.Description" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="ویرایش" />
</td>
</tr>
</table>
</form>
}

View File

@ -0,0 +1,74 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Auth.Memory;
using RMuseum.Models.Ganjoor;
namespace GanjooRazor.Areas.User.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class LanguageEditModel : PageModel
{
[BindProperty]
public GanjoorLanguage Language { get; set; }
public string LastMessage { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LastMessage = "";
await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
if (!ViewData.ContainsKey($"{RMuseumSecurableItem.GanjoorEntityShortName}-{RMuseumSecurableItem.Translations}"))
{
LastMessage = "شما به این بخش دسترسی ندارید.";
return Page();
}
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/languages/{Request.Query["id"]}");
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
response.EnsureSuccessStatusCode();
Language = JsonConvert.DeserializeObject<GanjoorLanguage>(await response.Content.ReadAsStringAsync());
}
else
{
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
using (HttpClient secureClient = new HttpClient())
{
await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response);
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/translations/languages", new StringContent(JsonConvert.SerializeObject(Language), Encoding.UTF8, "application/json"));
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
response.EnsureSuccessStatusCode();
return Redirect("/User/Languages");
}
}
}
}

View File

@ -113,7 +113,7 @@ else
<td>@($"{(language.RightToLeft ? "✅" : "⧠")}")</td>
<td>@language.Description</td>
<td>
<a role="button" href="/Admin/LanguageEdit/?id=@language.Id" class="actionlink" title="ویرایش">✎</a>
<a role="button" href="/User/LanguageEdit?id=@language.Id" class="actionlink" title="ویرایش">✎</a>
<a role="button" onclick="deleteLanguage(@language.Id, 'زبان')" class="actionlink" title="حذف">🗑</a>
</td>
</tr>