#129 rebuild donations page using UI

This commit is contained in:
Hamid Reza Mohammadi 2021-06-06 18:23:47 +04:30
parent 5f6b4a897f
commit ec55cbff91
3 changed files with 58 additions and 3 deletions

View File

@ -63,6 +63,8 @@
</form>
<p><a href="/donate" target="_blank">مشاهدهٔ صفحه</a></p>
<p>@Model.ShowAccountInfo</p>
<p><a role="button" onclick="rebuildDonationsPage()" class="actionlink" title="بازسازی صفحهٔ کمک‌ها">بازسازی صفحهٔ کمک‌ها</a></p>
@if (Model.Donations != null)
{

View File

@ -45,6 +45,11 @@ namespace GanjooRazor.Areas.Admin.Pages
/// </summary>
public GanjoorDonationViewModel[] Donations { get; set; }
/// <summary>
/// show account info
/// </summary>
public string ShowAccountInfo { get; set; }
private async Task ReadDonations()
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/donations");
@ -56,6 +61,22 @@ namespace GanjooRazor.Areas.Admin.Pages
response.EnsureSuccessStatusCode();
Donations = JsonConvert.DeserializeObject<GanjoorDonationViewModel[]>(await response.Content.ReadAsStringAsync());
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage resAccountInfo = await secureClient.GetAsync($"{APIRoot.Url}/api/donations/accountinfo/visible");
if (!resAccountInfo.IsSuccessStatusCode)
{
LastMessage = await resAccountInfo.Content.ReadAsStringAsync();
}
resAccountInfo.EnsureSuccessStatusCode();
ShowAccountInfo = JsonConvert.DeserializeObject<bool>(await resAccountInfo.Content.ReadAsStringAsync()) ? "نمایش حساب فعال است." : "نمایش حساب غیرفعال است.";
}
}
}
public async Task<IActionResult> OnGetAsync()
@ -106,10 +127,21 @@ namespace GanjooRazor.Areas.Admin.Pages
}
return Page();
}
public async Task<IActionResult> OnPostRebuildPageAsync()
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/donations/page", null);
response.EnsureSuccessStatusCode();
return new OkObjectResult(true);
}
}
return new OkObjectResult(false);
}
}
}

View File

@ -56,6 +56,27 @@
},
});
}
function rebuildDonationsPage() {
if (!confirm('آیا از بازسازی صفحهٔ کمک‌ها اطمینان دارید؟'))
return;
var url = '?handler=RebuildPage';
$.ajax({
type: "POST",
url: url,
error: function () {
alert('خطا رخ داد.')
},
success: function () {
alert('صفحه به درستی بازسازی شد.')
},
});
}
</script>
</head>