Popup.cs 2.7 KB

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