NotifyTemplate.cshtml.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Domain.Entities.Forum.Boards;
  2. using SharedKernel.Extensions;
  3. using MediatR;
  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 meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  32. Input = new InputModel
  33. {
  34. ID = meta.ID,
  35. BoardID = meta.BoardID,
  36. PostWriteEmailNotifySubject = meta.NotifyTemplate.PostWriteEmailNotifySubject,
  37. PostWriteEmailNotifyContent = meta.NotifyTemplate.PostWriteEmailNotifyContent,
  38. CommentWriteEmailNotifySubject = meta.NotifyTemplate.CommentWriteEmailNotifySubject,
  39. CommentWriteEmailNotifyContent = meta.NotifyTemplate.CommentWriteEmailNotifyContent,
  40. ReplyWriteEmailNotifySubject = meta.NotifyTemplate.ReplyWriteEmailNotifySubject,
  41. ReplyWriteEmailNotifyContent = meta.NotifyTemplate.ReplyWriteEmailNotifyContent
  42. };
  43. }
  44. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  45. {
  46. try
  47. {
  48. if (!ModelState.IsValid)
  49. {
  50. throw new Exception(ModelState.GetErrorMessages());
  51. }
  52. await mediator.Send(new UpdateBoardMeta.Command(
  53. Input.ID,
  54. Input.BoardID,
  55. null, null, null, null, null, null, null,
  56. new BoardMetaNotifyTemplate
  57. {
  58. PostWriteEmailNotifySubject = Input.PostWriteEmailNotifySubject,
  59. PostWriteEmailNotifyContent = Input.PostWriteEmailNotifyContent,
  60. CommentWriteEmailNotifySubject = Input.CommentWriteEmailNotifySubject,
  61. CommentWriteEmailNotifyContent = Input.CommentWriteEmailNotifyContent,
  62. ReplyWriteEmailNotifySubject = Input.ReplyWriteEmailNotifySubject,
  63. ReplyWriteEmailNotifyContent = Input.ReplyWriteEmailNotifyContent
  64. },
  65. null), ct);
  66. TempData["SuccessMessage"] = "알림 양식이 저장되었습니다.";
  67. }
  68. catch (Exception e)
  69. {
  70. TempData["ErrorMessages"] = e.Message;
  71. }
  72. return Redirect($"/Forum/Board/Meta/NotifyTemplate/{Input.BoardID}{Request.QueryString}");
  73. }
  74. }