MemberGrade.cs 3.6 KB

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