| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using Application.Features.Config;
- using Application.Features.Config.Commands;
- using Application.Features.Config.Queries;
- using MediatR;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- namespace Admin.Pages.Config
- {
- public class ExternalModel(IMediator mediator) : PageModel
- {
- [BindProperty]
- public InputModel Input { get; set; } = new();
- public async Task OnGetAsync(CancellationToken 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)
- {
- if (!ModelState.IsValid)
- {
- return Page();
- }
- await mediator.Send(Input.ToCommand(), cancellationToken);
- return RedirectToPage();
- }
- public sealed class InputModel
- {
- public ConfigDto.ExternalApiConfigDto External { get; set; } = new();
- public static InputModel From(ConfigDto config)
- {
- return new()
- {
- External = config.External
- };
- }
- public UpdateConfigCommand ToCommand()
- {
- return new(
- External : External
- );
- }
- }
- }
- }
|