Popup.cs 3.0 KB

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