| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using Application.Features.Config;
- using Application.Features.Config.Commands;
- using Application.Features.Config.Queries;
- using Application.Features.ReferenceData.Dtos;
- using Application.Features.ReferenceData.Queries;
- 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<BankCodeDto> BankCodes { get; set; } = [];
- private async Task BindBankCodesAsync(CancellationToken cancellationToken)
- {
- BankCodes = await mediator.Send(new GetBankCodesQuery(), cancellationToken);
- }
- public async Task OnGetAsync(CancellationToken cancellationToken)
- {
- await BindBankCodesAsync(cancellationToken);
- var config = await mediator.Send(new GetConfigQuery(), cancellationToken);
- if (config is not null)
- {
- Input = InputModel.From(config);
- }
- }
- public async Task<IActionResult> OnPostAsync(CancellationToken cancellationToken)
- {
- await BindBankCodesAsync(cancellationToken);
- if (!ModelState.IsValid)
- {
- return Page();
- }
- await mediator.Send(Input.ToCommand(), cancellationToken);
- return RedirectToPage();
- }
- public sealed class InputModel
- {
- public ConfigDto.CompanyConfigDto Company { get; set; } = new();
- public static InputModel From(ConfigDto config)
- {
- return new()
- {
- Company = config.Company
- };
- }
- public UpdateConfigCommand ToCommand()
- {
- return new(
- null,
- null,
- null,
- Company
- );
- }
- }
- }
- }
|