Document.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 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. Subject = subject;
  52. Content = content;
  53. IsActive = isActive;
  54. UpdatedAt = DateTime.UtcNow;
  55. }
  56. public void IncreaseViews()
  57. {
  58. Views++;
  59. }
  60. }
  61. }