Popup.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. namespace Domain.Entities.Page
  2. {
  3. public class Popup
  4. {
  5. public int ID { get; private set; }
  6. public string Subject { get; private set; } = default!;
  7. public string? Content { get; private set; }
  8. public string? Link { get; private set; }
  9. public DateTime? StartAt { get; private set; }
  10. public DateTime? EndAt { get; private set; }
  11. public short Order { get; private set; } = 0;
  12. public bool IsActive { get; private set; } = false;
  13. public DateTime? UpdatedAt { get; private set; }
  14. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  15. private Popup() { }
  16. private Popup(string subject, string? content, string? link, DateTime? startAt, DateTime? endAt, short order, bool isActive)
  17. {
  18. if (string.IsNullOrWhiteSpace(subject))
  19. {
  20. throw new ArgumentException("Subject is required.", nameof(subject));
  21. }
  22. if (subject.Length > 255)
  23. {
  24. throw new ArgumentOutOfRangeException(nameof(subject));
  25. }
  26. if (order < 0)
  27. {
  28. throw new ArgumentOutOfRangeException(nameof(order));
  29. }
  30. Subject = subject;
  31. Content = content;
  32. Link = link;
  33. StartAt = startAt;
  34. EndAt = endAt;
  35. Order = order;
  36. IsActive = isActive;
  37. }
  38. public static Popup Create(string subject, string? content = null, string? link = null, DateTime? startAt = null, DateTime? endAt = null, short order = 0, bool isActive = false)
  39. {
  40. return new(subject, content, link, startAt, endAt, order, isActive);
  41. }
  42. public void Update(string subject, string? content, string? link, DateTime? startAt, DateTime? endAt, short order, bool isActive)
  43. {
  44. if (string.IsNullOrWhiteSpace(subject))
  45. {
  46. throw new ArgumentException("Subject is required.", nameof(subject));
  47. }
  48. if (subject.Length > 255)
  49. {
  50. throw new ArgumentOutOfRangeException(nameof(subject));
  51. }
  52. if (order < 0)
  53. {
  54. throw new ArgumentOutOfRangeException(nameof(order));
  55. }
  56. Subject = subject;
  57. Content = content;
  58. Link = link;
  59. StartAt = startAt;
  60. EndAt = endAt;
  61. Order = order;
  62. IsActive = isActive;
  63. UpdatedAt = DateTime.UtcNow;
  64. }
  65. public void SetContent(string? content)
  66. {
  67. Content = content;
  68. UpdatedAt = DateTime.UtcNow;
  69. }
  70. }
  71. }