Document.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. namespace Domain.Entities.Page
  2. {
  3. public class Document
  4. {
  5. public int ID { get; private set; }
  6. public string Code { get; private set; } = default!;
  7. public string Subject { get; private set; } = default!;
  8. public string? Content { get; private set; }
  9. public bool IsActive { get; private set; } = false;
  10. public int Views { get; private set; } = 0;
  11. public DateTime? UpdatedAt { get; private set; }
  12. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  13. private Document() { }
  14. private Document(string code, string subject, string? content, 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 > 120)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(subject));
  31. }
  32. Code = code;
  33. Subject = subject;
  34. Content = content;
  35. IsActive = isActive;
  36. }
  37. public static Document Create(string code, string subject, string? content = null, bool isActive = false)
  38. {
  39. return new(code, subject, content, isActive);
  40. }
  41. public void Update(string code, string subject, string? content, bool isActive)
  42. {
  43. if (string.IsNullOrWhiteSpace(subject))
  44. {
  45. throw new ArgumentException("Subject is required.", nameof(subject));
  46. }
  47. if (subject.Length > 120)
  48. {
  49. throw new ArgumentOutOfRangeException(nameof(subject));
  50. }
  51. Code = code;
  52. Subject = subject;
  53. Content = content;
  54. IsActive = isActive;
  55. UpdatedAt = DateTime.UtcNow;
  56. }
  57. public void SetContent(string? content)
  58. {
  59. Content = content;
  60. UpdatedAt = DateTime.UtcNow;
  61. }
  62. public void IncreaseViews()
  63. {
  64. Views++;
  65. }
  66. }
  67. }