#129 UI for list of donations

This commit is contained in:
Hamid Reza Mohammadi 2021-06-06 13:09:50 +04:30
parent 2533e46b62
commit 9dadb05137
3 changed files with 104 additions and 1 deletions

View File

@ -0,0 +1,42 @@
@page
@model GanjooRazor.Areas.Admin.Pages.DonationsModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_AdminLayout";
ViewData["Title"] = "کمک‌های مالی";
}
<h1>@ViewData["Title"]</h1>
<p>@Model.LastMessage</p>
@if (Model.Donations != null)
{
<table>
<tr>
<th>#</th>
<th>تاریخ</th>
<th>مبلغ</th>
<th>اهدا کننده</th>
<th>
#
</th>
</tr>
@foreach (var donation in Model.Donations)
{
<tr id="tr-@donation.Id">
<td><a href="/Admin/DonationEdit/?od=@donation.Id">@donation.Id</a> </td>
<td>@donation.DateString</td>
<td>@donation.AmountString</td>
<td>@donation.DonorName</td>
<td>
<a role="button" href="/Admin/DonationEdit/?od=@donation.Id" class="actionlink" title="ویرایش">✎</a>
<a role="button" onclick="deleteDonation(@donation.Id)" class="actionlink" title="حذف">🗑</a>
</td>
</tr>
}
</table>
}

View File

@ -0,0 +1,53 @@
using System.Net.Http;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Accounting.ViewModels;
namespace GanjooRazor.Areas.Admin.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class DonationsModel : PageModel
{
/// <summary>
/// last message
/// </summary>
public string LastMessage { get; set; }
/// <summary>
/// donations
/// </summary>
public GanjoorDonationViewModel[] Donations { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/donations");
if (!response.IsSuccessStatusCode)
{
LastMessage = await response.Content.ReadAsStringAsync();
}
response.EnsureSuccessStatusCode();
Donations = JsonConvert.DeserializeObject<GanjoorDonationViewModel[]>(await response.Content.ReadAsStringAsync());
}
else
{
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
}
}

View File

@ -73,7 +73,15 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="Admin" asp-page="Banners">آگاهی‌ها</a>
</li>
</ul>
</div>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="Admin" asp-page="Donations">کمک‌های مالی</a>
</li>
</ul>
</div>
</div>