/// <summary> /// A parameterkent kapott Filet feldolgozza es az igy kapott Flightot menti az adatbazisba. /// </summary> /// <param name="file">Feldolgozando File</param> /// <returns>Igaz az adatok sikeres mentese eseten, egyebkent hamis</returns> public override async Task ProcessFile() { var files = await context.LogFiles.ToListAsync(); foreach (var file in files) { if (!file.Processed) { file.Processed = true; await context.SaveChangesAsync(); bool result = false; var flight = GetFlightFromLogFile(file); context.Flights.Add(flight); result = await context.SaveChangesAsync() > 0; if (result) { context.Files.Remove(file); } else { file.Processed = false; } await context.SaveChangesAsync(); } } }
public async Task <bool> InsertFilesAsync(List <Model.Models.File> files) { foreach (var f in files) { context.Files.Add(f); } return(await context.SaveChangesAsync() > 0); }
/// <summary> /// A parameterkent kapott Filet feldolgozza es az igy kapott Airportokat menti az adatbazisba. /// </summary> /// <param name="file">Feldolgozando File</param> /// <returns>Igaz az adatok sikeres mentese eseten, egyebkent hamis</returns> public override async Task ProcessFile() { var files = await context.AirportFiles.ToListAsync(); foreach (var file in files) { if (!file.Processed) { file.Processed = true; await context.SaveChangesAsync(); bool result = false; var excelData = GetExcelDataFromFile(file); var airports = GetAirportsFromExcelData(excelData); foreach (var a in airports) { if (!context.Airports.Select(ai => ai.Name).Contains(a.Name)) { context.Airports.Add(a); } } result = await context.SaveChangesAsync() > 0; if (result) { context.Files.Remove(file); } else { file.Processed = false; } await context.SaveChangesAsync(); } } }
public async Task UpdateFlightAsync(Flight flight) { context.Attach(flight).State = EntityState.Modified; //Mappeleskor duplikalodna foreach (var dl in context.AirportFlights.Where(af => af.FlightId.Equals(flight.Id))) { context.AirportFlights.Remove(dl); } await context.SaveChangesAsync(); }