| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- namespace Domain.Entities.Page.Faq
- {
- public class FaqItem
- {
- [ForeignKey(nameof(CategoryID))]
- public virtual FaqCategory FaqCategory { get; private set; } = null!;
- [Key]
- public int ID { get; private set; }
- public int CategoryID { get; private set; }
- public string Question { get; private set; } = default!;
- public string? Answer { 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 FaqItem() { }
- private FaqItem(int categoryID, string question, string? answer, short order, bool isActive)
- {
- if (categoryID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(categoryID));
- }
- if (string.IsNullOrWhiteSpace(question))
- {
- throw new ArgumentException("Question is required.", nameof(question));
- }
- if (question.Length > 255)
- {
- throw new ArgumentOutOfRangeException(nameof(question));
- }
- if (order < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(order));
- }
- CategoryID = categoryID;
- Question = question;
- Answer = answer;
- Order = order;
- IsActive = isActive;
- }
- public static FaqItem Create(int categoryID, string question, string? answer = null, short order = 0, bool isActive = false)
- {
- return new(categoryID, question, answer, order, isActive);
- }
- public void Update(int categoryID, string question, string? answer, short order, bool isActive)
- {
- if (categoryID <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(categoryID));
- }
- if (string.IsNullOrWhiteSpace(question))
- {
- throw new ArgumentException("Question is required.", nameof(question));
- }
- if (question.Length > 255)
- {
- throw new ArgumentOutOfRangeException(nameof(question));
- }
- if (order < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(order));
- }
- CategoryID = categoryID;
- Question = question;
- Answer = answer;
- Order = order;
- IsActive = isActive;
- UpdatedAt = DateTime.UtcNow;
- }
- public void SetContent(string? answer)
- {
- Answer = answer;
- UpdatedAt = DateTime.UtcNow;
- }
- }
- }
|