private void buttonImport_Click(object sender, EventArgs e) { try { if (openFileDialog1.ShowDialog() == DialogResult.OK) { var docPath = openFileDialog1.FileName; var source = new ExcelQueryFactory(docPath); List <Author> authors = new List <Author>(); var authorId = context.Authors.Max(a => a.AuthorID) + 1; foreach (var row in source.Worksheet(0).AsEnumerable()) { Author au = new Author() { AuthorID = authorId, Name = row[0].Cast <string>().Trim(), GenderID = row[1].Cast <int>(), EducationLevelID = row[2].Cast <int>(), PeriodID = row[3].Cast <int>(), NationalityID = row[4].Cast <int>(), }; authors.Add(au); authorId++; } List <Book> books = new List <Book>(); int bookId = context.Books.Max(a => a.BookID) + 1; foreach (var row in source.Worksheet(0).AsEnumerable()) { Book book = new Book() { BookID = bookId, Text = row[5].Cast <string>(), TempAuthorName = row[0].Cast <string>().Trim() }; books.Add(book); bookId++; } foreach (Book book in books) { TextManager.AnalyzeText(book); book.AuthorID = authors.Where(a => a.Name == book.TempAuthorName).FirstOrDefault().AuthorID; } context.Authors.AddRange(authors); context.Books.AddRange(books); context.SaveChanges(); } } catch (DbEntityValidationException) { throw; } }
private void ProcessBookText() { CurrentBook = new Book(); CurrentBook.BookID = context.Books.Max(b => b.BookID) + 1; CurrentBook.Text = richTextBox1.Text; TextManager.AnalyzeText(CurrentBook); //int counter = context.NamedEntities.Max(e => e.NamedEntityID) + 1; //foreach (var entiry in CurrentBook.NamedEntities) //{ // entiry.NamedEntityID = counter;counter++; //} CurrentBook.Author = CurrentAuthor; }