Handler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Application.Abstractions.Cache;
  4. using SharedKernel.Storage;
  5. namespace Application.Features.Admin.Popup.Create;
  6. public sealed class Handler(IAppDbContext db, IEditorImageService editorImage, ICacheService cache) : ICommandHandler<Command, int>
  7. {
  8. public async Task<int> Handle(Command request, CancellationToken ct)
  9. {
  10. if (request.StartAt > request.EndAt)
  11. {
  12. throw new Exception("�˾��� �������� �����Ϻ��� ������ �� �����ϴ�.");
  13. }
  14. var popup = Domain.Entities.Page.Popup.Popup.Create(
  15. request.PositionID,
  16. request.Subject,
  17. null,
  18. request.Link,
  19. request.StartAt,
  20. request.EndAt,
  21. request.Order,
  22. request.IsActive
  23. );
  24. await db.Popup.AddAsync(popup);
  25. await db.SaveChangesAsync(ct);
  26. var path = new FileStoragePath(UploadTarget.Editor, UploadFolder.Popup, popup.ID);
  27. var html = await editorImage.UploadAsync(request.Content, path, ct);
  28. popup.SetContent(html);
  29. await db.SaveChangesAsync(ct);
  30. await cache.RemoveByPrefixAsync("popup:", ct);
  31. return popup.ID;
  32. }
  33. }