82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DramaLing.Api.Models.Entities;
|
|
|
|
/// <summary>
|
|
/// 選項詞彙庫實體 - 用於生成測驗選項的詞彙資料庫
|
|
/// </summary>
|
|
[Index(nameof(Word), IsUnique = true, Name = "IX_OptionsVocabulary_Word")]
|
|
[Index(nameof(CEFRLevel), Name = "IX_OptionsVocabulary_CEFR")]
|
|
[Index(nameof(PartOfSpeech), Name = "IX_OptionsVocabulary_PartOfSpeech")]
|
|
[Index(nameof(WordLength), Name = "IX_OptionsVocabulary_WordLength")]
|
|
[Index(nameof(IsActive), Name = "IX_OptionsVocabulary_Active")]
|
|
[Index(nameof(CEFRLevel), nameof(PartOfSpeech), nameof(WordLength), Name = "IX_OptionsVocabulary_Core_Matching")]
|
|
public class OptionsVocabulary
|
|
{
|
|
/// <summary>
|
|
/// 主鍵
|
|
/// </summary>
|
|
public Guid Id { get; set; }
|
|
|
|
/// <summary>
|
|
/// 詞彙內容
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(100)]
|
|
public string Word { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// CEFR 難度等級 (A1, A2, B1, B2, C1, C2)
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(2)]
|
|
[RegularExpression("^(A1|A2|B1|B2|C1|C2)$",
|
|
ErrorMessage = "CEFR等級必須為A1, A2, B1, B2, C1, C2之一")]
|
|
public string CEFRLevel { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 詞性 (noun, verb, adjective, adverb, pronoun, preposition, conjunction, interjection, idiom)
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(20)]
|
|
[RegularExpression("^(noun|verb|adjective|adverb|pronoun|preposition|conjunction|interjection|idiom)$",
|
|
ErrorMessage = "詞性必須為有效值")]
|
|
public string PartOfSpeech { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 字數(字元長度)- 自動從 Word 計算
|
|
/// </summary>
|
|
public int WordLength { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否啟用
|
|
/// </summary>
|
|
public bool IsActive { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 創建時間
|
|
/// </summary>
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
/// <summary>
|
|
/// 更新時間
|
|
/// </summary>
|
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
/// <summary>
|
|
/// 自動計算字數
|
|
/// </summary>
|
|
public void CalculateWordLength()
|
|
{
|
|
WordLength = Word?.Length ?? 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新時間戳
|
|
/// </summary>
|
|
public void UpdateTimestamp()
|
|
{
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
} |