| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Application.Features.Director.GetUser;
- using Application.Features.Director.UpdateUser;
- using MediatR;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- namespace Admin.Pages.Director.User
- {
- public class EditModel(IMediator mediator) : PageModel
- {
- [BindProperty]
- public Response? Input { get; set; }
- public async Task OnGetAsync(string id, CancellationToken ct)
- {
- var user = await mediator.Send(new GetUserQuery(id), ct);
- if (user != null)
- {
- Input = new Response
- {
- ID = user.ID,
- Name = user.FullName,
- Email = user.Email,
- Phone = user.PhoneNumber,
- IsDeleted = user.IsDeleted,
- EmailConfirmed = user.EmailConfirmed,
- LockoutEnd = user.LockoutEnd.HasValue,
- Roles = user.Roles
- };
- }
- }
- public async Task<IActionResult> OnPostAsync(CancellationToken ct)
- {
- try
- {
- if (!ModelState.IsValid)
- {
- throw new Exception("유효성 검사에 실패하였습니다.");
- }
- var command = new UpdateUserCommand(
- ID: Input!.ID,
- FullName: Input.Name,
- Email: Input.Email,
- NewPassword: Input.NewPassword,
- ConfirmPassword: Input.ConfirmPassword,
- PhoneNumber: Input.Phone,
- IsDeleted: Input.IsDeleted,
- EmailConfirmed: Input.EmailConfirmed,
- LockoutEnd: Input.LockoutEnd
- );
- await mediator.Send(command, ct);
- TempData["SuccessMessage"] = "사용자 정보가 정상적으로 수정되었습니다.";
- return RedirectToPage(command);
- }
- catch (Exception e)
- {
- TempData["ErrorMessages"] = e.Message;
- return Page();
- }
- }
- }
- }
|