CoinCategory.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Crypto
  3. {
  4. public class CoinCategory
  5. {
  6. public virtual List<CoinCategoryMap> CoinCategoryMap { get; private set; } = [];
  7. [Key]
  8. public int ID { get; private set; }
  9. public string Code { get; private set; } = default!;
  10. public string Name { get; private set; } = default!;
  11. public short Order { get; private set; } = 0;
  12. public bool IsActive { get; private set; } = false;
  13. public DateTime? UpdatedAt { get; private set; }
  14. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  15. private CoinCategory() { }
  16. private CoinCategory(string code, string name, short order, bool isActive)
  17. {
  18. if (string.IsNullOrWhiteSpace(code))
  19. {
  20. throw new ArgumentException("Code is required.", nameof(code));
  21. }
  22. if (code.Length > 30)
  23. {
  24. throw new ArgumentOutOfRangeException(nameof(code));
  25. }
  26. if (string.IsNullOrWhiteSpace(name))
  27. {
  28. throw new ArgumentException("Name is required.", nameof(name));
  29. }
  30. if (name.Length > 100)
  31. {
  32. throw new ArgumentOutOfRangeException(nameof(name));
  33. }
  34. if (order < 0)
  35. {
  36. throw new ArgumentOutOfRangeException(nameof(order));
  37. }
  38. Code = code;
  39. Name = name;
  40. Order = order;
  41. IsActive = isActive;
  42. }
  43. public static CoinCategory Create(string code, string name, short order = 0, bool isActive = false)
  44. {
  45. return new(code, name, order, isActive);
  46. }
  47. public void Update(string code, string name, short order, bool isActive)
  48. {
  49. if (string.IsNullOrWhiteSpace(code))
  50. {
  51. throw new ArgumentException("Code is required.", nameof(code));
  52. }
  53. if (code.Length > 30)
  54. {
  55. throw new ArgumentOutOfRangeException(nameof(code));
  56. }
  57. if (string.IsNullOrWhiteSpace(name))
  58. {
  59. throw new ArgumentException("Name is required.", nameof(name));
  60. }
  61. if (name.Length > 100)
  62. {
  63. throw new ArgumentOutOfRangeException(nameof(name));
  64. }
  65. if (order < 0)
  66. {
  67. throw new ArgumentOutOfRangeException(nameof(order));
  68. }
  69. Code = code;
  70. Name = name;
  71. Order = order;
  72. IsActive = isActive;
  73. UpdatedAt = DateTime.UtcNow;
  74. }
  75. }
  76. }