public void SaveSubtitleNewWords(IList <SubtitleWord> newWords, string subtitleName) { BeginTran(); var q = Session.CreateSQLQuery("delete from Subtitle_NewWord where SubtitleName='" + subtitleName.Replace("'", "''") + "'"); q.ExecuteUpdate(); foreach (var userNewWord in newWords.Distinct()) { Subtitle_NewWord entity = new Subtitle_NewWord() { Word = userNewWord.Word, SubtitleName = subtitleName, Sentence = userNewWord.SubtitleSentence, WordMean = userNewWord.SelectMean }; Session.SaveOrUpdate(entity); UserVocabulary vocabulary = FindOne <UserVocabulary>(v => v.Word == userNewWord.Word); if (vocabulary == null) { vocabulary = new UserVocabulary(); } vocabulary.Word = userNewWord.Word; vocabulary.Source = "Subtitle"; vocabulary.KnownStatus = KnownStatus.Unknown; Session.SaveOrUpdate(vocabulary); } Commit(); }
//public void SaveUserKnownWords(IList<string> words) //{ // BeginTran(); // foreach (var w in words) // { // Subtitle_KnownWord word = new Subtitle_KnownWord() {AddTime = DateTime.Now, Word = w}; // context.KnownWords.Add(word); // UserVocabulary vocabulary = context.UserVocabulary.SingleOrDefault(v => v.Word == w); // if (vocabulary == null) // { // vocabulary = new UserVocabulary(); // } // vocabulary.Word = w; // vocabulary.Source = "Subtitle"; // vocabulary.KnownStatus = KnownStatus.Known; // context.UserVocabulary.AddOrUpdate(vocabulary); // context.SaveChanges(); // } // Commit(); //} //public UserVocabulary GetUserVocabulary(string word) //{ // return FindFirst<UserVocabulary>(v => v.Word == word); //} public void SaveSubtitleNewWords(IList <SubtitleWord> newWords, string subtitleName) { BeginTran(); RunSql("delete from Subtitle_NewWord where SubtitleName='" + subtitleName.Replace("'", "''") + "'"); foreach (var userNewWord in newWords.Distinct()) { Subtitle_NewWord entity = new Subtitle_NewWord() { Word = userNewWord.Word, SubtitleName = subtitleName, Sentence = userNewWord.SubtitleSentence, WordMean = userNewWord.SelectMean, CreateTime = DateTime.Now, KnownStatus = userNewWord.IsNewWord?KnownStatus.Unknown : KnownStatus.Known }; context.NewWords.Add(entity); UserVocabulary vocabulary = context.UserVocabulary.SingleOrDefault(v => v.Word == userNewWord.Word); if (vocabulary == null) { vocabulary = new UserVocabulary(); vocabulary.CreateTime = DateTime.Now; } vocabulary.Word = userNewWord.Word; vocabulary.Source = "字幕"; vocabulary.Sentence = userNewWord.SubtitleSentence; vocabulary.KnownStatus = userNewWord.IsNewWord ? KnownStatus.Unknown : KnownStatus.Known; vocabulary.UpdateTime = DateTime.Now; context.UserVocabulary.AddOrUpdate(vocabulary); context.SaveChanges(); } Commit(); }