Category.cs 2.6 KB

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