Category.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. namespace Domain.Entities.Page.Faq
  2. {
  3. public class FaqCategory
  4. {
  5. public virtual List<FaqItem> FaqItems { get; private set; } = [];
  6. public int ID { get; private set; }
  7. public string Code { get; private set; } = default!;
  8. public string Subject { get; private set; } = default!;
  9. public short Order { get; private set; } = 0;
  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 FaqCategory() { }
  14. private FaqCategory(string code, string subject, short order, 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. if (order < 0)
  33. {
  34. throw new ArgumentOutOfRangeException(nameof(order));
  35. }
  36. Code = code;
  37. Subject = subject;
  38. Order = order;
  39. IsActive = isActive;
  40. }
  41. public static FaqCategory Create(string code, string subject, short order = 0, bool isActive = false)
  42. {
  43. return new(code, subject, order, isActive);
  44. }
  45. public void Update(string code, string subject, short order, bool isActive)
  46. {
  47. if (string.IsNullOrWhiteSpace(code))
  48. {
  49. throw new ArgumentException("Code is required.", nameof(code));
  50. }
  51. if (string.IsNullOrWhiteSpace(subject))
  52. {
  53. throw new ArgumentException("Subject is required.", nameof(subject));
  54. }
  55. if (subject.Length > 255)
  56. {
  57. throw new ArgumentOutOfRangeException(nameof(subject));
  58. }
  59. if (order < 0)
  60. {
  61. throw new ArgumentOutOfRangeException(nameof(order));
  62. }
  63. Code = code;
  64. Subject = subject;
  65. Order = order;
  66. IsActive = isActive;
  67. UpdatedAt = DateTime.UtcNow;
  68. }
  69. }
  70. }