Item.cs 2.7 KB

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