public static bool InsertTermToDatabase(string term) { var termObj = Wiktionary.GetTerm(term); if (termObj.entries.Count() > 0) { bool termExists = (db.Exists <Term>("WHERE text = @0", termObj.term)); var dbTerm = new Term(); dbTerm.text = termObj.term; var termId = termExists? db.Single <Term>("WHERE text = @0", termObj.term).id : (int)db.Insert(dbTerm); DeleteOldDefinitions(termId); var defs = termObj.entries.SelectMany(e => e.definitions).Select(obj => DefinitionObjectToModel(obj, termId)); InsertNewDefinitions(defs); var examples = termObj.entries.SelectMany(e => e.definitions).SelectMany(d => d.examples).SelectMany(e => e).Select(e => ExampleObjectToModel(e)); var newExamples = examples.Where(e => !db.Exists <Example>("WHERE text = @0", e.text)); InsertNewExamples(newExamples); return(true); } return(false); }
private static void TestWord(string term) { var termObj = Wiktionary.GetTerm(term); var termJson = JsonConvert.SerializeObject(termObj, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Console.Write(termJson); }