public Document GetDocument(string path) { XmlSerializer xml = new XmlSerializer(typeof(Quran)); var quran = xml.Deserialize(new StreamReader(path)) as Quran; Document document = new Document(); var chapters = new List<Chapter>(114); foreach (var sura in quran.Suras) { var chapter = new Chapter() { Id = sura.Index, Name = sura.Name }; var verses = new List<Verse>(sura.Ayas.Count()); var index = 0; foreach (var aya in sura.Ayas) { var verse = new Verse() { Chapter = chapter, Id = aya.Index, Index = ++index }; var tokens = new List<Token>(); var splitTokens = aya.Text.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i <= splitTokens.Count(); i++) { var splitToken = splitTokens[i-1]; var token = new Token() { Id = i, Text = splitToken }; tokens.Add(token); } verse.Tokens = tokens; verses.Add(verse); } chapter.Verses = verses; chapters.Add(chapter); } document.Chapters = chapters; return document; }
public void Import(Document document) { var context = new StraightPathDbContext(); context.Documents.Add(document); context.SaveChanges(); }