Position.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. namespace Domain.Entities.Page.Banner
  2. {
  3. public class BannerPosition
  4. {
  5. public virtual List<BannerItem> BannerItems { get; private set; } = [];
  6. public int ID { get; private set; }
  7. public string Code { get; private set; } = default!;
  8. public string Subject { get; private set; } = default!;
  9. public bool IsActive { get; private set; } = false;
  10. public DateTime? UpdatedAt { get; private set; }
  11. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  12. private BannerPosition() { }
  13. private BannerPosition(string code, string subject, bool isActive)
  14. {
  15. if (string.IsNullOrWhiteSpace(code))
  16. {
  17. throw new ArgumentException("Code is required.", nameof(code));
  18. }
  19. if (code.Length > 30)
  20. {
  21. throw new ArgumentOutOfRangeException(nameof(code));
  22. }
  23. if (string.IsNullOrWhiteSpace(subject))
  24. {
  25. throw new ArgumentException("Subject is required.", nameof(subject));
  26. }
  27. if (subject.Length > 255)
  28. {
  29. throw new ArgumentOutOfRangeException(nameof(subject));
  30. }
  31. Code = code;
  32. Subject = subject;
  33. IsActive = isActive;
  34. }
  35. public static BannerPosition Create(string code, string subject, bool isActive = false)
  36. {
  37. return new(code, subject, isActive);
  38. }
  39. public void Update(string subject, bool isActive)
  40. {
  41. if (string.IsNullOrWhiteSpace(subject))
  42. {
  43. throw new ArgumentException("Subject is required.", nameof(subject));
  44. }
  45. if (subject.Length > 255)
  46. {
  47. throw new ArgumentOutOfRangeException(nameof(subject));
  48. }
  49. Subject = subject;
  50. IsActive = isActive;
  51. UpdatedAt = DateTime.UtcNow;
  52. }
  53. }
  54. }