NotifyTemplate.cshtml.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Domain.Entities.Forum.Boards;
  2. using SharedKernel.Extensions;
  3. using Application.Abstractions.Messaging;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.RazorPages;
  6. namespace Admin.Pages.Forum.Board.Meta;
  7. public class NotifyTemplateModel(IMediator mediator) : PageModel
  8. {
  9. public int BoardID { get; set; }
  10. public List<(int ID, string Name)> BoardList { get; set; } = [];
  11. public string? QueryString { get; set; }
  12. [BindProperty]
  13. public InputModel Input { get; set; } = new();
  14. public sealed class InputModel
  15. {
  16. public int ID { get; set; }
  17. public int BoardID { get; set; }
  18. public string? PostWriteEmailNotifySubject { get; set; }
  19. public string? PostWriteEmailNotifyContent { get; set; }
  20. public string? CommentWriteEmailNotifySubject { get; set; }
  21. public string? CommentWriteEmailNotifyContent { get; set; }
  22. public string? ReplyWriteEmailNotifySubject { get; set; }
  23. public string? ReplyWriteEmailNotifyContent { get; set; }
  24. }
  25. public async Task OnGetAsync(int id, CancellationToken ct)
  26. {
  27. BoardID = id;
  28. QueryString = Request.QueryString.ToString();
  29. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  30. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  31. var metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct);
  32. if (metaResult.IsFailure)
  33. {
  34. TempData["ErrorMessages"] = metaResult.Error.Description;
  35. return;
  36. }
  37. var meta = metaResult.Value;
  38. Input = new InputModel
  39. {
  40. ID = meta.ID,
  41. BoardID = meta.BoardID,
  42. PostWriteEmailNotifySubject = meta.NotifyTemplate.PostWriteEmailNotifySubject,
  43. PostWriteEmailNotifyContent = meta.NotifyTemplate.PostWriteEmailNotifyContent,
  44. CommentWriteEmailNotifySubject = meta.NotifyTemplate.CommentWriteEmailNotifySubject,
  45. CommentWriteEmailNotifyContent = meta.NotifyTemplate.CommentWriteEmailNotifyContent,
  46. ReplyWriteEmailNotifySubject = meta.NotifyTemplate.ReplyWriteEmailNotifySubject,
  47. ReplyWriteEmailNotifyContent = meta.NotifyTemplate.ReplyWriteEmailNotifyContent
  48. };
  49. }
  50. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  51. {
  52. if (!ModelState.IsValid)
  53. {
  54. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  55. return Redirect($"/Forum/Board/Meta/NotifyTemplate/{Input.BoardID}{Request.QueryString}");
  56. }
  57. var result = await mediator.Send(new UpdateBoardMeta.Command(
  58. Input.ID,
  59. Input.BoardID,
  60. null, null, null, null, null, null, null,
  61. new BoardMetaNotifyTemplate
  62. {
  63. PostWriteEmailNotifySubject = Input.PostWriteEmailNotifySubject,
  64. PostWriteEmailNotifyContent = Input.PostWriteEmailNotifyContent,
  65. CommentWriteEmailNotifySubject = Input.CommentWriteEmailNotifySubject,
  66. CommentWriteEmailNotifyContent = Input.CommentWriteEmailNotifyContent,
  67. ReplyWriteEmailNotifySubject = Input.ReplyWriteEmailNotifySubject,
  68. ReplyWriteEmailNotifyContent = Input.ReplyWriteEmailNotifyContent
  69. },
  70. null), ct);
  71. if (result.IsFailure)
  72. {
  73. TempData["ErrorMessages"] = result.Error.Description;
  74. }
  75. else
  76. {
  77. TempData["SuccessMessage"] = "알림 양식이 저장되었습니다.";
  78. }
  79. return Redirect($"/Forum/Board/Meta/NotifyTemplate/{Input.BoardID}{Request.QueryString}");
  80. }
  81. }