PopupPosition.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Page.Popup;
  3. public class PopupPosition
  4. {
  5. public virtual List<Popup> Popups { get; private set; } = [];
  6. [Key]
  7. public int ID { get; private set; }
  8. public string Code { get; private set; } = default!;
  9. public string Subject { get; private set; } = default!;
  10. public bool IsActive { get; private set; } = false;
  11. public DateTime? UpdatedAt { get; private set; }
  12. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  13. private PopupPosition() { }
  14. private PopupPosition(string code, string subject, bool isActive)
  15. {
  16. if (string.IsNullOrWhiteSpace(code))
  17. {
  18. throw new ArgumentException("Code is required.", nameof(code));
  19. }
  20. if (code.Length > 30)
  21. {
  22. throw new ArgumentOutOfRangeException(nameof(code));
  23. }
  24. if (string.IsNullOrWhiteSpace(subject))
  25. {
  26. throw new ArgumentException("Subject is required.", nameof(subject));
  27. }
  28. if (subject.Length > 255)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(subject));
  31. }
  32. Code = code;
  33. Subject = subject;
  34. IsActive = isActive;
  35. }
  36. public static PopupPosition Create(string code, string subject, bool isActive = false)
  37. {
  38. return new(code, subject, isActive);
  39. }
  40. public void Update(string subject, bool isActive)
  41. {
  42. if (string.IsNullOrWhiteSpace(subject))
  43. {
  44. throw new ArgumentException("Subject is required.", nameof(subject));
  45. }
  46. if (subject.Length > 255)
  47. {
  48. throw new ArgumentOutOfRangeException(nameof(subject));
  49. }
  50. Subject = subject;
  51. IsActive = isActive;
  52. UpdatedAt = DateTime.UtcNow;
  53. }
  54. }