#203 delete language

This commit is contained in:
Hamid Reza Mohammadi 2021-09-14 19:22:22 +04:30
parent 597d57743d
commit 7aa3524fc8
3 changed files with 44 additions and 7 deletions

View File

@ -72,6 +72,29 @@ else
@if (Model.Languages != null)
{
<script>
function deleteLanguage(itemId, itemName) {
if (!confirm('آیا از حذف این ' + itemName + ' اطمینان دارید؟'))
return;
$.ajax({
type: "DELETE",
url: '',
data: {
id: itemId
},
error: function () {
alert('خطا رخ داد.');
},
success: function () {
location.reload();
return false;
},
});
}
</script>
<table>
<tr>
<th>نام</th>

View File

@ -34,7 +34,7 @@ namespace GanjooRazor.Areas.User.Pages
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/langugages");
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/languages");
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
@ -62,7 +62,7 @@ namespace GanjooRazor.Areas.User.Pages
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PostAsync($"{APIRoot.Url}/api/translations/langugages", new StringContent(JsonConvert.SerializeObject(Language), Encoding.UTF8, "application/json"));
HttpResponseMessage response = await secureClient.PostAsync($"{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());
@ -82,5 +82,19 @@ namespace GanjooRazor.Areas.User.Pages
return Page();
}
public async Task<IActionResult> OnDeleteAsync(int id)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/translations/languages/{id}");
response.EnsureSuccessStatusCode();
return new OkObjectResult(true);
}
}
return new OkObjectResult(false);
}
}
}

View File

@ -19,7 +19,7 @@ namespace RMuseum.Controllers
/// get all languages
/// </summary>
/// <returns></returns>
[HttpGet("langugages")]
[HttpGet("languages")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLanguage[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
@ -37,7 +37,7 @@ namespace RMuseum.Controllers
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("langugages/{id}")]
[HttpGet("languages/{id}")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLanguage))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
@ -54,7 +54,7 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="lang"></param>
/// <returns></returns>
[HttpPost("langugages")]
[HttpPost("languages")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.Translations)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLanguage))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
@ -72,7 +72,7 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="lang"></param>
/// <returns></returns>
[HttpPut("langugages")]
[HttpPut("languages")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.Translations)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
@ -85,7 +85,7 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
[HttpDelete("langugages/{id}")]
[HttpDelete("languages/{id}")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.Translations)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]