public void ImportAirlineReportsFromDirectory(string path) { var files = GetReportsFileNamesFromDirectory(path); using (AirportsDbContextMySql dbContext = new AirportsDbContextMySql()) { foreach (var file in files) { string fileContent = File.ReadAllText(file); Airlinereport report = JsonConvert.DeserializeObject<Airlinereport>(fileContent); dbContext.Add(report); } dbContext.SaveChanges(); } }
public void GenerateCompositeAirlinesReport(string path) { Console.WriteLine("Generating merged report from SQLite and MySql..."); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } SLDocument excelFile = new SLDocument(); using (AirportsDbContextSQLite sqliteDbContext = new AirportsDbContextSQLite()) { using (AirportsDbContextMySql mysqlDbContext = new AirportsDbContextMySql()) { var compositeReports = from report in mysqlDbContext.Airlinereports.AsEnumerable() join airline in sqliteDbContext.Airlines.AsEnumerable() on report.AirlineName equals airline.Name select new { report.AirlineName, report.TotalFlightsCount, report.AverageFlightsCount, report.TotalFlightsDuration, report.StartDate, report.EndDate, airline.Website, airline.FoundationYear }; excelFile.SetCellValue("A1", "Airline Name"); excelFile.SetCellValue("B1", "Total Flights Count"); excelFile.SetCellValue("C1", "Average Flights Duration"); excelFile.SetCellValue("D1", "Total Flights Duration"); excelFile.SetCellValue("E1", "From Date"); excelFile.SetCellValue("F1", "To Date"); excelFile.SetCellValue("G1", "Company Website"); excelFile.SetCellValue("H1", "Foundation Year"); int rowCounter = 2; foreach (var report in compositeReports) { excelFile.SetCellValue("A" + rowCounter, report.AirlineName); excelFile.SetCellValue("B" + rowCounter, report.TotalFlightsCount.ToString()); excelFile.SetCellValue("C" + rowCounter, report.AverageFlightsCount.ToString()); excelFile.SetCellValue("D" + rowCounter, report.TotalFlightsDuration.ToString()); excelFile.SetCellValue("E" + rowCounter, report.StartDate.ToString()); excelFile.SetCellValue("F" + rowCounter, report.EndDate.ToString()); excelFile.SetCellValue("G" + rowCounter, report.Website.ToString()); excelFile.SetCellValue("H" + rowCounter, report.FoundationYear.ToString()); rowCounter++; } } } DateTime currentDate = DateTime.Now; string fileNameSuffix = string.Format("-{0}.{1}.{2}-{3}.{4}.{5}.pdf", currentDate.Day, currentDate.Month, currentDate.Year, currentDate.Hour, currentDate.Minute, currentDate.Second); excelFile.SaveAs(string.Format("{0}AirlineRepors_{1}.xlsx", path, fileNameSuffix)); }