| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using SharedKernel.Extensions;
- using Application.Abstractions.Messaging;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using System.ComponentModel.DataAnnotations;
- using GetGameGenres = Application.Features.Admin.Store.GameGenre.GetAll;
- using SaveGameGenres = Application.Features.Admin.Store.GameGenre.Save;
- namespace Admin.Pages.Store;
- public class GameGenreModel(IMediator mediator) : PageModel
- {
- public int Total { get; private set; }
- public List<(
- int Num,
- int ID,
- int Index,
- string KorName,
- string? EngName,
- int Order,
- char IsActive,
- int GameCount,
- string? UpdatedAt,
- string CreatedAt
- )> List { get; set; } = [];
- [BindProperty(Name = "request")]
- public List<InputModel> Input { get; private set; } = [];
- public List<InputModel> Data { get; private set; } = [];
- public sealed class InputModel
- {
- public int? ID { get; set; }
- [Required]
- [StringLength(100)]
- public required string KorName { get; set; }
- [StringLength(100)]
- public string? EngName { get; set; }
- [Range(-9999, 9999)]
- public int Order { get; set; }
- public bool IsActive { get; set; } = false;
- }
- public async Task OnGetAsync(CancellationToken ct)
- {
- if (!ModelState.IsValid)
- {
- return;
- }
- var result = await mediator.Send(new GetGameGenres.Query(), ct);
- Total = result.Total;
- List = [.. result.List.Select(c => (
- c.Num,
- c.ID,
- c.Index,
- c.KorName,
- c.EngName,
- c.Order,
- c.IsActive ? 'Y' : 'N',
- c.GameCount,
- c.UpdatedAt.GetDateAt() ?? "-",
- c.CreatedAt.GetDateAt()
- ))];
- Data = [.. result.List.Select(x => new InputModel
- {
- ID = x.ID,
- KorName = x.KorName,
- EngName = x.EngName,
- Order = x.Order,
- IsActive = x.IsActive
- })];
- }
- public async Task<IActionResult> OnPostAsync(CancellationToken ct)
- {
- if (!ModelState.IsValid)
- {
- TempData["ErrorMessages"] = ModelState.GetErrorMessages();
- return RedirectToPage("/Store/GameGenre");
- }
- var cmd = new SaveGameGenres.Command(
- [.. Input.Select(x => new SaveGameGenres.Command.Row(
- x.ID,
- x.KorName,
- x.EngName,
- x.Order,
- x.IsActive
- ))]
- );
- var result = await mediator.Send(cmd, ct);
- if (result.IsFailure)
- {
- TempData["ErrorMessages"] = result.Error.Description;
- }
- else
- {
- var response = result.Value;
- TempData["SuccessMessage"] = $"저장 완료 (추가: {response.Inserted}, 수정: {response.Updated}, 삭제: {response.Deleted})";
- }
- return RedirectToPage("/Store/GameGenre");
- }
- }
|