MemberGrade.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. namespace Domain.Entities.Members
  2. {
  3. public class MemberGrade
  4. {
  5. public int ID { get; private set; }
  6. public string KorName { get; private set; } = default!;
  7. public string EngName { get; private set; } = default!;
  8. public string? Description { get; private set; }
  9. public short Order { get; private set; } = 0;
  10. public string? Image { get; private set; }
  11. public string? TextColor { get; private set; }
  12. public int RequiredExp { get; private set; } = 0;
  13. public long RequiredAttendance { get; private set; } = 0;
  14. public bool IsActive { get; private set; } = false;
  15. public DateTime? UpdatedAt { get; private set; }
  16. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  17. private MemberGrade() { }
  18. private MemberGrade(string korName, string engName, short order, bool isActive)
  19. {
  20. if (string.IsNullOrWhiteSpace(korName))
  21. {
  22. throw new ArgumentException("KorName is required.", nameof(korName));
  23. }
  24. if (korName.Length > 240)
  25. {
  26. throw new ArgumentOutOfRangeException(nameof(korName));
  27. }
  28. if (string.IsNullOrWhiteSpace(engName))
  29. {
  30. throw new ArgumentException("EngName is required.", nameof(engName));
  31. }
  32. if (engName.Length > 120)
  33. {
  34. throw new ArgumentOutOfRangeException(nameof(engName));
  35. }
  36. if (order < 0)
  37. {
  38. throw new ArgumentOutOfRangeException(nameof(order));
  39. }
  40. KorName = korName;
  41. EngName = engName;
  42. Order = order;
  43. IsActive = isActive;
  44. }
  45. public static MemberGrade Create(string korName, string engName, short order = 0, bool isActive = false)
  46. {
  47. return new(korName, engName, order, isActive);
  48. }
  49. public void Update(string korName, string engName, string? description, short order, string? image, string? textColor, int requiredExp, long requiredAttendance, bool isActive)
  50. {
  51. if (string.IsNullOrWhiteSpace(korName))
  52. {
  53. throw new ArgumentException("KorName is required.", nameof(korName));
  54. }
  55. if (korName.Length > 240)
  56. {
  57. throw new ArgumentOutOfRangeException(nameof(korName));
  58. }
  59. if (string.IsNullOrWhiteSpace(engName))
  60. {
  61. throw new ArgumentException("EngName is required.", nameof(engName));
  62. }
  63. if (engName.Length > 120)
  64. {
  65. throw new ArgumentOutOfRangeException(nameof(engName));
  66. }
  67. if (description is not null && description.Length > 1000)
  68. {
  69. throw new ArgumentOutOfRangeException(nameof(description));
  70. }
  71. if (order < 0)
  72. {
  73. throw new ArgumentOutOfRangeException(nameof(order));
  74. }
  75. if (image is not null && image.Length > 1000)
  76. {
  77. throw new ArgumentOutOfRangeException(nameof(image));
  78. }
  79. if (textColor is not null && textColor.Length > 7)
  80. {
  81. throw new ArgumentOutOfRangeException(nameof(textColor));
  82. }
  83. if (requiredExp < 0)
  84. {
  85. throw new ArgumentOutOfRangeException(nameof(requiredExp));
  86. }
  87. if (requiredAttendance < 0)
  88. {
  89. throw new ArgumentOutOfRangeException(nameof(requiredAttendance));
  90. }
  91. KorName = korName;
  92. EngName = engName;
  93. Description = description;
  94. Order = order;
  95. Image = image;
  96. TextColor = textColor;
  97. RequiredExp = requiredExp;
  98. RequiredAttendance = requiredAttendance;
  99. IsActive = isActive;
  100. UpdatedAt = DateTime.UtcNow;
  101. }
  102. }
  103. }