NavMenuItem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. namespace Domain.Entities.Common;
  2. public class NavMenuItem
  3. {
  4. public int ID { get; private set; }
  5. public string Label { get; private set; } = default!;
  6. public string Href { get; private set; } = default!;
  7. public int SortOrder { get; private set; } = 0;
  8. public bool IsVisible { get; private set; } = true;
  9. public DateTime UpdatedAt { get; private set; } = DateTime.UtcNow;
  10. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  11. private NavMenuItem() { }
  12. private NavMenuItem(string label, string href, int sortOrder, bool isVisible)
  13. {
  14. if (string.IsNullOrWhiteSpace(label))
  15. {
  16. throw new ArgumentException("Label is required.", nameof(label));
  17. }
  18. if (label.Length > 50)
  19. {
  20. throw new ArgumentOutOfRangeException(nameof(label));
  21. }
  22. if (string.IsNullOrWhiteSpace(href))
  23. {
  24. throw new ArgumentException("Href is required.", nameof(href));
  25. }
  26. if (href.Length > 200)
  27. {
  28. throw new ArgumentOutOfRangeException(nameof(href));
  29. }
  30. Label = label;
  31. Href = href;
  32. SortOrder = sortOrder;
  33. IsVisible = isVisible;
  34. }
  35. public static NavMenuItem Create(string label, string href, int sortOrder, bool isVisible)
  36. {
  37. return new(label, href, sortOrder, isVisible);
  38. }
  39. public void Update(string label, string href, int sortOrder, bool isVisible)
  40. {
  41. if (string.IsNullOrWhiteSpace(label))
  42. {
  43. throw new ArgumentException("Label is required.", nameof(label));
  44. }
  45. if (label.Length > 50)
  46. {
  47. throw new ArgumentOutOfRangeException(nameof(label));
  48. }
  49. if (string.IsNullOrWhiteSpace(href))
  50. {
  51. throw new ArgumentException("Href is required.", nameof(href));
  52. }
  53. if (href.Length > 200)
  54. {
  55. throw new ArgumentOutOfRangeException(nameof(href));
  56. }
  57. Label = label;
  58. Href = href;
  59. SortOrder = sortOrder;
  60. IsVisible = isVisible;
  61. UpdatedAt = DateTime.UtcNow;
  62. }
  63. public void SetVisible(bool isVisible)
  64. {
  65. IsVisible = isVisible;
  66. UpdatedAt = DateTime.UtcNow;
  67. }
  68. }