Position.cs 2.0 KB

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