MemberGrade.cs 4.0 KB

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