| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- namespace Domain.Entities.Page.Popup
- {
- public class Popup
- {
- [ForeignKey(nameof(PositionID))]
- public virtual PopupPosition PopupPosition { get; private set; } = null!;
- [Key]
- public int ID { get; private set; }
- public int PositionID { get; private set; }
- public string Subject { get; private set; } = default!;
- public string? Content { get; private set; }
- public string? Link { get; private set; }
- public DateTime? StartAt { get; private set; }
- public DateTime? EndAt { get; private set; }
- public short Order { get; private set; } = 0;
- public bool IsActive { get; private set; } = false;
- public DateTime? UpdatedAt { get; private set; }
- public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
- private Popup() { }
- private Popup(int positionID, string subject, string? content, string? link, DateTime? startAt, DateTime? endAt, short order, bool isActive)
- {
- if (positionID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(positionID));
- }
- if (string.IsNullOrWhiteSpace(subject))
- {
- throw new ArgumentException("Subject is required.", nameof(subject));
- }
- if (subject.Length > 255)
- {
- throw new ArgumentOutOfRangeException(nameof(subject));
- }
- if (order < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(order));
- }
- PositionID = positionID;
- Subject = subject;
- Content = content;
- Link = link;
- StartAt = startAt;
- EndAt = endAt;
- Order = order;
- IsActive = isActive;
- }
- public static Popup Create(int positionID, string subject, string? content = null, string? link = null, DateTime? startAt = null, DateTime? endAt = null, short order = 0, bool isActive = false)
- {
- return new(positionID, subject, content, link, startAt, endAt, order, isActive);
- }
- public void Update(int positionID, string subject, string? content, string? link, DateTime? startAt, DateTime? endAt, short order, bool isActive)
- {
- if (positionID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(positionID));
- }
- if (string.IsNullOrWhiteSpace(subject))
- {
- throw new ArgumentException("Subject is required.", nameof(subject));
- }
- if (subject.Length > 255)
- {
- throw new ArgumentOutOfRangeException(nameof(subject));
- }
- if (order < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(order));
- }
- PositionID = positionID;
- Subject = subject;
- Content = content;
- Link = link;
- StartAt = startAt;
- EndAt = endAt;
- Order = order;
- IsActive = isActive;
- UpdatedAt = DateTime.UtcNow;
- }
- public void SetContent(string? content)
- {
- Content = content;
- UpdatedAt = DateTime.UtcNow;
- }
- }
- }
|