| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using SharedKernel.Extensions;
- using Application.Abstractions.Messaging;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using Infrastructure.Persistence.Identity;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- namespace Admin.Pages.Store.Settlement;
- public class DetailModel(IMediator mediator, UserManager<ApplicationUser> userManager) : PageModel
- {
- public GetGameSettlement.Response? Data { get; private set; }
- [BindProperty]
- public SettleInput Input { get; set; } = new();
- public sealed class SettleInput
- {
- [DisplayName("관리자 메모")]
- [StringLength(500, ErrorMessage = "{0}은(는) {1}자 이하로 입력하세요.")]
- public string? AdminMemo { get; set; }
- }
- public async Task OnGetAsync(int id, CancellationToken ct)
- {
- await LoadAsync(id, ct);
- }
- public async Task<IActionResult> OnPostMarkSettledAsync(int id, CancellationToken ct)
- {
- if (!ModelState.IsValid)
- {
- TempData["ErrorMessages"] = ModelState.GetErrorMessages();
- return RedirectToPage("/Store/Settlement/Detail", new { id });
- }
- var admin = await userManager.GetUserAsync(User);
- if (admin is null)
- {
- TempData["ErrorMessages"] = "관리자 정보를 확인할 수 없습니다.";
- return RedirectToPage("/Store/Settlement/Detail", new { id });
- }
- var result = await mediator.Send(new MarkSettlementSettled.Command(
- id, admin.Id, admin.Email, Input.AdminMemo
- ), ct);
- TempData[result.IsFailure ? "ErrorMessages" : "SuccessMessage"] =
- result.IsFailure ? result.Error.Description : "정산 완료로 처리되었습니다.";
- return RedirectToPage("/Store/Settlement/Detail", new { id });
- }
- private async Task LoadAsync(int id, CancellationToken ct)
- {
- var result = await mediator.Send(new GetGameSettlement.Query(id), ct);
- if (result.IsFailure)
- {
- TempData["ErrorMessages"] = result.Error.Description;
- return;
- }
- Data = result.Value;
- Input.AdminMemo = Data.AdminMemo;
- }
- }
|