docs: #285 deleting a FAQ category

This commit is contained in:
Hamid Reza Mohammadi 2022-03-03 09:33:33 +03:30
parent 91a2cc8c58
commit d6c33683c6
2 changed files with 50 additions and 0 deletions

View File

@ -19,6 +19,32 @@ else
function editCategory(){
location.href = '/User/FAQCatEdit?id=' + String(document.getElementById('cat').value);
}
function deleteCategory() {
var sel = document.getElementById('cat');
var text= sel.options[sel.selectedIndex].text;
if (!confirm('آیا از حذف '+text+' اطمینان دارید؟'))
return;
$.ajax({
type: "DELETE",
url: '',
data: {
id: sel.value
},
error: function (e) {
if (e.responseText == null)
alert(e);
else
alert(e.responseText);
},
success: function () {
location.reload();
},
});
}
</script>
<table>
<tr>
@ -31,6 +57,7 @@ else
}
</select>
<a role="button" onclick="editCategory()" class="actionlink" title="ویرایش"><i class="noindent-info-button edit-poem-button"></i></a>
<a role="button" onclick="deleteCategory()" class="actionlink" title="حذف"><i class="noindent-info-button delete-icon"></i></a>
</td>
</tr>
<tr>

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Auth.Memory;
using RMuseum.Models.FAQ;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
@ -50,5 +51,27 @@ 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/faq/cat/{id}");
if (response.StatusCode != HttpStatusCode.OK)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
}
}
else
{
return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید.");
}
}
return new JsonResult(true);
}
}
}