Exemplo n.º 1
0
        public void FindWord()
        {

            string db_name = "Dictionary_FindWord.db"; 

            EFDbContext db;
            db = RecreateDB(db_name);

            Dictionary dic = new Dictionary();
            db.AddNewItemToDBContext(dic);

            WordOfDictionary wrd0 = new WordOfDictionary();
            wrd0.word_of_dictionary = "Test";
            dic.Words.Add(wrd0);

            WordOfDictionary wrd1 = new WordOfDictionary();
            wrd1.word_of_dictionary = "I am";

            wrd1.AddForm("I'm");
            Assert.IsTrue(wrd1.Forms == "[i'm]");

            wrd1.RemoveForm("I'm");
            Assert.IsTrue(wrd1.Forms == "");

            wrd1.AddForm("I'm");
            dic.Words.Add(wrd1);

            WordOfDictionary wrd2 = new WordOfDictionary();
            wrd2.word_of_dictionary = "Hello";
            dic.Words.Add(wrd2);

            db.SaveChanges();
            db.Close();


            db = ConnectToDb(db_name);
            dic = db.FirstOrDefault<Dictionary>();

            WordOfDictionary fwrd = dic.FindWord("I'm");
            Assert.IsTrue(fwrd.word_of_dictionary == "I am");

            fwrd = dic.FindWord("I am");
            Assert.IsTrue(fwrd.word_of_dictionary == "I am");

            db.Close();

        }
Exemplo n.º 2
0
        /*
        public List<WordOfSubtitleItem> FindReferences(WordOfDictionary wrd)
        {
            return DBContext.Query<WordOfSubtitleItem>(new QueryBuilder(DBContext) { Where = $"{nameof(WordOfSubtitleItem.word_of_dictionary_id)} = '{wrd.id.Hex}'"});
        } 
        */

        public void MergeWords(WordOfDictionary DestWord,WordOfDictionary DeletedWord)
        {
            if (DBContext == null) throw new Exception("DbContext not initialized");

            DestWord.AddForm(DeletedWord.word_of_dictionary);
            
            //DBContext.Delete(DeletedWord);
            if (Words.Contains(DeletedWord))
            {
                Words.Remove(DeletedWord);
            } else
            {
                DBContext.Delete(DeletedWord);
            }

            //string sql = "SELECT * FROM " + WordOfSubtitleItem.TableName + " WHERE word_of_dictionary_id = " + DeletedWord.id.Hex;
            List<WordOfSubtitleItem> lst = DBContext.Query(new QueryBuilder<WordOfSubtitleItem>(DBContext) {Where= $"{nameof(WordOfSubtitleItem.word_of_dictionary_id)} = '{DeletedWord.id.Hex}'"});
            foreach(WordOfSubtitleItem elm in lst)
            {
                elm.word_of_dictionary = DestWord;
            }

        }