Company.cshtml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using GetBank = Application.Features.Admin.ReferenceData.GetBank;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. namespace Admin.Pages.Config;
  6. public class CompanyModel(IMediator mediator) : PageModel
  7. {
  8. [BindProperty]
  9. public InputModel Input { get; set; } = new();
  10. public IReadOnlyList<GetBank.Response> BankCodes { get; set; } = [];
  11. private async Task BindBankCodesAsync(CancellationToken ct)
  12. {
  13. BankCodes = await mediator.Send(new GetBank.Query(), ct);
  14. }
  15. public async Task OnGetAsync(CancellationToken ct)
  16. {
  17. await BindBankCodesAsync(ct);
  18. var config = await mediator.Send(new GetConfig.Query(), ct);
  19. if (config is not null)
  20. {
  21. Input = InputModel.From(config);
  22. }
  23. }
  24. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  25. {
  26. await BindBankCodesAsync(ct);
  27. if (!ModelState.IsValid)
  28. {
  29. return Page();
  30. }
  31. await mediator.Send(Input.ToCommand(), ct);
  32. TempData["SuccessMessage"] = "저장되었습니다.";
  33. return RedirectToPage();
  34. }
  35. public sealed class InputModel
  36. {
  37. public UpdateConfig.Request.CompanyConfigDto Company { get; set; } = new();
  38. public static InputModel From(GetConfig.Response config)
  39. {
  40. var req = UpdateConfig.Request.From(config);
  41. return new()
  42. {
  43. Company = req.Company
  44. };
  45. }
  46. public UpdateConfig.Command ToCommand()
  47. {
  48. return new(
  49. Company: Company
  50. );
  51. }
  52. }
  53. }