docs: #285 create and edit FAQ items
This commit is contained in:
parent
3b4ba00a8c
commit
058c8296b1
@ -5,6 +5,7 @@ using Newtonsoft.Json;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.FAQ;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GanjooRazor.Areas.User.Pages
|
||||
@ -62,5 +63,26 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response);
|
||||
HttpResponseMessage response =
|
||||
Question.Id == 0 ?
|
||||
await secureClient.PostAsync($"{APIRoot.Url}/api/faq", new StringContent(JsonConvert.SerializeObject(Question), Encoding.UTF8, "application/json"))
|
||||
:
|
||||
await secureClient.PutAsync($"{APIRoot.Url}/api/faq", new StringContent(JsonConvert.SerializeObject(Question), Encoding.UTF8, "application/json"))
|
||||
;
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
return Page();
|
||||
}
|
||||
|
||||
return Redirect($"/User/FAQItems?catId={Question.CategoryId}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ else
|
||||
success: function (items) {
|
||||
var s = '';
|
||||
for(var i=0; i<items.length; i++){
|
||||
s += ('<p><a href="/FAQItemEdit?id='+String(items[i].id)+'">' + '<p>' + items[i].question + '</a></p>');
|
||||
s += ('<p><a href="/User/FAQItemEdit?id='+String(items[i].id)+'">' + '<p>' + items[i].question + '</a></p>');
|
||||
}
|
||||
document.getElementById('catItems').innerHTML = s;
|
||||
},
|
||||
@ -84,7 +84,14 @@ else
|
||||
<select name="cat" id="cat" onchange="onSelectedCatChanged()">
|
||||
@foreach (var category in Model.Categories)
|
||||
{
|
||||
<option value="@category.Id">@category.Title</option>
|
||||
@if(category.Id == Model.CatId)
|
||||
{
|
||||
<option value="@category.Id" selected>@category.Title</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@category.Id">@category.Title</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<a role="button" onclick="editCategory()" class="actionlink" title="ویرایش"><i class="noindent-info-button edit-poem-button"></i></a>
|
||||
@ -103,6 +110,10 @@ else
|
||||
<a role="button" onclick="newItem()" class="pagebutton">پرسش جدید</a>
|
||||
</p>
|
||||
<div id="catItems">
|
||||
@foreach(var item in Model.CategoryItems)
|
||||
{
|
||||
<p><a href="/User/FAQItemEdit?id=@item.Id">@item.Question</a></p>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@ -17,6 +17,10 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
|
||||
public FAQCategory[] Categories { get; set; }
|
||||
|
||||
public FAQItem[] CategoryItems { get; set; }
|
||||
|
||||
public int CatId { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
if(string.IsNullOrEmpty(Request.Cookies["Token"]))
|
||||
@ -30,6 +34,8 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
CatId = 0;
|
||||
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
@ -43,6 +49,24 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
|
||||
Categories = JsonConvert.DeserializeObject<FAQCategory[]>(await response.Content.ReadAsStringAsync());
|
||||
|
||||
if(Categories.Length > 0)
|
||||
{
|
||||
CatId = string.IsNullOrEmpty(Request.Query["catId"]) ? Categories[0].Id : int.Parse(Request.Query["catId"]);
|
||||
response = await secureClient.GetAsync($"{APIRoot.Url}/api/faq/cat/items?catId={CatId}");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
||||
}
|
||||
|
||||
var items = JsonConvert.DeserializeObject<FAQItem[]>(await response.Content.ReadAsStringAsync());
|
||||
if (items == null)
|
||||
{
|
||||
items = new FAQItem[] { };
|
||||
}
|
||||
|
||||
CategoryItems = items;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -80,7 +104,7 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/faq/cat/secure/items?catId={id}");
|
||||
HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/faq/cat/items?catId={id}");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user