public bool AddInformationToTheDb(string fileName) { using (var fileInfoRepository = new FileInfoRepository()) { try { var fileInfo = new Parser(new ReadWriter(fileName)).ParseFile(); fileInfoRepository.Add(fileInfo); fileInfoRepository.SaveChanges(); return true; } catch { var unverifiedFiles = new UnverifiedFilesRepository { new UnverifiedFile(fileName) }; unverifiedFiles.SaveChanges(); return false; } } }
public void AddInformationToTheDb(string fileName) { AddLog("start add information"); try { var records = new Reader(fileName).Read(); var parser = new Parser(); var fileInformation = parser.ParseFileName(fileName); using (var fileInformationRepository = new FileInformationRepository()) { fileInformationRepository.Add(fileInformation); fileInformation = fileInformationRepository.FileObjectByName(fileInformation.Name); using (var saleInfoRepository = new SaleInfoRepository()) { foreach (var record in records) { var saleInfo = parser.ParseRecord(record); saleInfo.FileInformation = fileInformation; lock (Locker) { saleInfoRepository.Add(saleInfo); } } } } } catch (Exception ex) { Console.WriteLine("exception " + ex.Message); //throw; } AddLog("add infromation OK "); }