| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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 MetaModel(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.MetaConfigDto Meta { get; set; } = new();
- public static InputModel From(ConfigDto config)
- {
- return new()
- {
- Meta = config.Meta
- };
- }
- public UpdateConfigCommand ToCommand()
- {
- return new(
- null,
- null,
- Meta
- );
- }
- }
- }
- }
|