internal static void AddVocabularyWord(string wordStr, int id, string owner) { if (string.IsNullOrEmpty(owner)) { throw new Exception("Owner needed"); } bool isList = VocabularyList.Exists("WHERE ID = @0 AND OwnerID = @1", id, owner); if (!isList) { throw new Exception("Unknown list"); } Word word = Word.FirstOrDefault("WHERE Word=@0", wordStr); if (word == null) { throw new Exception(String.Format("Unknown word {0}", wordStr)); } VocabularyList_Word vlw = new VocabularyList_Word(); vlw.VocabularyListID = id; vlw.WordID = word.ID; vlw.Insert(); }
internal static List <FullWord> GetFullWordListByListID(int id) { List <VocabularyList_Word> vlWords = VocabularyList_Word.Fetch("WHERE VocabularyListID = @0 ORDER BY Rank", id); int[] wordIDs = vlWords.Select(t => t.WordID).ToArray(); List <FullWord> vlFW = SuomenkieliRepository.GetFullWordList(wordIDs); return(vlFW); }
internal static void OrderVocabularyList(string list, int[] order) { List <VocabularyList_Word> vlWords = VocabularyList_Word.Fetch("WHERE VocabularyListID = @0", list); Sql updateSQL = new Sql(@"UPDATE [VocabularyList_Word] SET Rank = CASE WordID"); for (int i = 0; i < order.Length; i++) { int wordID = order[i]; VocabularyList_Word vlWord = vlWords.First(w => w.WordID == wordID); vlWord.Rank = i; updateSQL.Append("WHEN @0 THEN @1", wordID, i); //vlWord.Update(); // TODO: A more efficient version. } updateSQL.Append("END"); updateSQL.Append("WHERE VocabularyListID=@0 AND WordID IN (@1)", list, order); db.Execute(updateSQL); }