public void EnsureSeedData() { if (!_context.Chapters.Any() || !_context.Annotations.Any()) { Chapter newChapter = new Chapter(); newChapter.EntireChapterString = System.IO.File.ReadAllText("./../ch08.txt"); _context.Chapters.Add(newChapter); string json = System.IO.File.ReadAllText("./../ch08.txt.json"); JArray jsonArray = JArray.Parse(json) as JArray; dynamic items = jsonArray; foreach (dynamic item in items) { Annotation annotation = item.ToObject<Annotation>(); _context.Annotations.Add(annotation); } _context.SaveChanges(); } }
public void AddChapter(Chapter chapter) { _context.Chapters.Add(chapter); }