| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using GetBank = Application.Features.ReferenceData.GetBank;
- using MediatR;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- namespace Admin.Pages.Config
- {
- public class CompanyModel(IMediator mediator) : PageModel
- {
- [BindProperty]
- public InputModel Input { get; set; } = new();
- public IReadOnlyList<GetBank.Response> BankCodes { get; set; } = [];
- private async Task BindBankCodesAsync(CancellationToken ct)
- {
- BankCodes = await mediator.Send(new GetBank.Query(), ct);
- }
- public async Task OnGetAsync(CancellationToken ct)
- {
- await BindBankCodesAsync(ct);
- var config = await mediator.Send(new GetConfig.Query(), ct);
- if (config is not null)
- {
- Input = InputModel.From(config);
- }
- }
- public async Task<IActionResult> OnPostAsync(CancellationToken ct)
- {
- await BindBankCodesAsync(ct);
- if (!ModelState.IsValid)
- {
- return Page();
- }
- await mediator.Send(Input.ToCommand(), ct);
- return RedirectToPage();
- }
- public sealed class InputModel
- {
- public UpdateConfig.Request.CompanyConfigDto Company { get; set; } = new();
- public static InputModel From(GetConfig.Response config)
- {
- var req = UpdateConfig.Request.From(config);
- return new()
- {
- Company = req.Company
- };
- }
- public UpdateConfig.Command ToCommand()
- {
- return new(
- Company: Company
- );
- }
- }
- }
- }
|