public void UpdateDb() { lock (lockObj) { string filePath = Path.Combine(_appEnvironment.ContentRootPath, "wwwroot/Files/Result.txt"); if (!System.IO.File.Exists(filePath)) { return; } // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(filePath); foreach (string line in lines) { if (line == "") { continue; } string[] obj = line.Split(";").ToArray <string>(); var word = new Word { English = obj[0], Russian = obj[1] }; _wordService.Create(word); //word = _wordService.GetByEng(word.English); string vocabularyName = obj[2] + " " + obj[3]; bool exist = _vocabularyService.IsExist(vocabularyName); Vocabulary vocabulary; if (exist) { vocabulary = _vocabularyService.GetByName(vocabularyName); } else { vocabulary = new Vocabulary { LevelId = int.Parse(obj[3]), IsPrivate = false, Name = vocabularyName }; _vocabularyService.Create(vocabulary); //vocabulary = _vocabularyService.GetByName(vocabulary.Name); } _vocabularyService.AddWord(word.Id, vocabulary.Id); } } }