using Application.Abstractions.Identity.Models; using Application.Abstractions.Messaging; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace Admin.Pages.Director.User; public class RolesModel(IMediator mediator) : PageModel { [BindProperty] public required GetUserRoles.Response Input { get; set; } public async Task OnGetAsync(string id, CancellationToken ct) { if (string.IsNullOrEmpty(id)) { TempData["ErrorMessages"] = "유효하지 않은 접근입니다."; return RedirectToPage("/Director/User/Index"); } var result = await mediator.Send(new GetUserRoles.Query(id), ct); if (result.IsFailure) { TempData["ErrorMessages"] = result.Error.Description; return RedirectToPage("/Director/User/Index"); } Input = result.Value; return Page(); } public async Task OnPostAsync(CancellationToken ct) { if (!ModelState.IsValid) { TempData["ErrorMessages"] = "유효성 검사에 실패하였습니다."; return Page(); } var command = new UpdateUserRoles.Command( Input!.User.ID, new UserRolesDto { Roles = [.. (Input.Roles ?? []).Select(r => new UserRolesDto.Checkbox { DisplayValue = r.DisplayValue, IsSelected = r.IsSelected })] } ); await mediator.Send(command, ct); TempData["SuccessMessage"] = "권한이 변경되었습니다."; return RedirectToPage(new { id = Input.User.ID }); } }