| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System.ComponentModel.DataAnnotations;
- namespace Domain.Entities.Page.Faq
- {
- public class FaqCategory
- {
- public virtual List<FaqItem> FaqItems { get; private set; } = [];
- [Key]
- public int ID { get; private set; }
- public string Code { get; private set; } = default!;
- public string Subject { get; private set; } = default!;
- 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 FaqCategory() { }
- private FaqCategory(string code, string subject, short order, bool isActive)
- {
- if (string.IsNullOrWhiteSpace(code))
- {
- throw new ArgumentException("Code is required.", nameof(code));
- }
- if (code.Length > 30)
- {
- throw new ArgumentOutOfRangeException(nameof(code));
- }
- 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));
- }
- Code = code;
- Subject = subject;
- Order = order;
- IsActive = isActive;
- }
- public static FaqCategory Create(string code, string subject, short order = 0, bool isActive = false)
- {
- return new(code, subject, order, isActive);
- }
- public void Update(string code, string subject, short order, bool isActive)
- {
- if (string.IsNullOrWhiteSpace(code))
- {
- throw new ArgumentException("Code is required.", nameof(code));
- }
- 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));
- }
- Code = code;
- Subject = subject;
- Order = order;
- IsActive = isActive;
- UpdatedAt = DateTime.UtcNow;
- }
- }
- }
|