divan/DiwanRazor/Areas/Admin/Pages/DonationEdit.cshtml.cs
Anas Rashid e8f2306422 Rename Ganjoor -> Diwan throughout the code
Projects (GanjooRazor -> DiwanRazor, GanjoorService.sln -> DiwanService.sln), files,
folders, classes, namespaces, settings, API routes (/api/diwan) and DB tables (Diwan*).
External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed
consistently (no pending model changes); requires a fresh database.
Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 23:49:01 +02:00

76 lines
2.5 KiB
C#

using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using DiwanRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Accounting.ViewModels;
namespace DiwanRazor.Areas.Admin.Pages
{
public class DonationEditModel : PageModel
{
/// <summary>
/// HttpClient instance
/// </summary>
private readonly HttpClient _httpClient;
/// <summary>
/// constructor
/// </summary>
/// <param name="httpClient"></param>
public DonationEditModel(HttpClient httpClient)
{
_httpClient = httpClient;
}
[BindProperty]
public UpdateDateDescriptionViewModel Donation { get; set; }
public string LastMessage { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/donations/{Request.Query["id"]}");
if(!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
var donation = JsonConvert.DeserializeObject<DiwanDonationViewModel>(await response.Content.ReadAsStringAsync());
Donation = new UpdateDateDescriptionViewModel()
{
Date = donation.RecordDate,
Description = donation.DonorName
};
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient(new DiwanReloginHandler(Request, Response)))
{
await DiwanSessionChecker.PrepareClient(secureClient, Request, Response);
HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/donations/{Request.Query["id"]}", new StringContent(JsonConvert.SerializeObject(Donation), Encoding.UTF8, "application/json"));
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
return Redirect("/Admin/Donations");
}
}
}
}