Handler.cs 932 B

12345678910111213141516171819202122232425262728293031323334
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Popup.Update;
  5. public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
  6. {
  7. public async Task Handle(Command request, CancellationToken ct)
  8. {
  9. if (request.StartAt > request.EndAt)
  10. {
  11. throw new Exception("팝업의 종료일은 시작일보다 이전일 수 없습니다.");
  12. }
  13. var popup = await db.Popup.FirstOrDefaultAsync(x => x.ID == request.ID, ct);
  14. if (popup is null)
  15. {
  16. throw new Exception("팝업을 찾을 수 없습니다.");
  17. }
  18. popup.Update(
  19. request.Subject,
  20. request.Content,
  21. request.Link,
  22. request.StartAt,
  23. request.EndAt,
  24. request.Order,
  25. request.IsActive
  26. );
  27. await db.SaveChangesAsync(ct);
  28. }
  29. }