public static async Task <VatsimClientPilotV1> FindPilotAsync(string cid, string callsign, string timelogon) { using (var db = new VatsimDbContext()) { return(await db.Pilots.FindAsync(cid, callsign, timelogon)); } }
public static async void UpdateOrCreatePilot(VatsimClientPilot pilot) { using (var db = new VatsimDbContext()) { var _pilot = await db.Pilots.FindAsync(pilot.Cid, pilot.Callsign, pilot.TimeLogon); // didn't find the pilot if (_pilot == null) { db.Add(pilot); db.SaveChanges(); Log.Information($"Added Pilot: {pilot} to DB"); } else { DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_pilot.TimeLogon); DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(pilot.TimeLogon); if (new_time > old_time) { db.Add(pilot); db.SaveChanges(); Log.Information($"Added Pilot: {pilot} to DB"); } else { _pilot.Update(pilot); db.Update(_pilot); db.SaveChanges(); Log.Information($"Updated Pilot: {pilot} in DB"); } } } }
public static async Task <VatsimClientATCV1> FindControllerAsync(string cid, string callsign, string timelogon) { using (var db = new VatsimDbContext()) { return(await db.Controllers.FindAsync(cid, callsign, timelogon)); } }
public static async void UpdateOrCreateATC(VatsimClientATC controller) { using (var db = new VatsimDbContext()) { var _controller = await db.Controllers.FindAsync(controller.Cid, controller.Callsign, controller.TimeLogon); // didn't find the pilot if (_controller == null) { db.Add(controller); db.SaveChanges(); Log.Information($"Added Controller: {controller} to DB"); } else { DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_controller.TimeLogon); DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(controller.TimeLogon); if (new_time > old_time) { db.Add(controller); Log.Information($"Added Controller: {controller} to DB"); db.SaveChanges(); } else { _controller.Update(controller); db.Update(_controller); db.SaveChanges(); Log.Information($"Updated Controller: {controller} in DB"); } } } }
public static async void UpdateControllersFromListAsync(IEnumerable <VatsimClientATCV1> controllers) { using (var db = new VatsimDbContext()) { db.Controllers.UpdateRange(controllers); await db.SaveChangesAsync(); } }
public static async void UpdateFlightsFromListAsync(IEnumerable <VatsimClientPlannedFlightV1> flights) { using (var db = new VatsimDbContext()) { db.Flights.UpdateRange(flights); await db.SaveChangesAsync(); } }
public static async void UpdatePilotsFromListAsync(IEnumerable <VatsimClientPilotV1> pilots) { using (var db = new VatsimDbContext()) { db.Pilots.UpdateRange(pilots); await db.SaveChangesAsync(); } }
public static async void CreatePositionsFromListAsync(IEnumerable <VatsimClientPilotSnapshotV1> positions) { using (var db = new VatsimDbContext()) { await db.Positions.AddRangeAsync(positions); await db.SaveChangesAsync(); } }
public static async void CreateATCFromListAsync(IEnumerable <VatsimClientATCV1> controllers) { using (var db = new VatsimDbContext()) { await db.Controllers.AddRangeAsync(controllers); await db.SaveChangesAsync(); } }
/// <summary> /// Save a position to the database /// </summary> /// <param name="position">position snapshot information</param> public static void CreatePosition(VatsimClientPilotSnapshot position) { using (var db = new VatsimDbContext()) { // make sure we have a position to write if (position != null) { db.Add(position); db.SaveChanges(); Log.Information($"Added Position: {position} to DB"); } } }
public static async Task <VatsimClientPlannedFlightV1> FindFlightAsync( string cid, string callsign, string timelogon, string dep, string dest) { using (var db = new VatsimDbContext()) { return(await db.Flights.FindAsync(cid, callsign, timelogon, dep, dest)); } }
public static async void UpdateOrCreateFlightAsync(VatsimClientPlannedFlightV1 flight) { using (var db = new VatsimDbContext()) { var _flight = await FindFlightAsync(flight.Cid, flight.Callsign, flight.TimeLogon, flight.PlannedDepairport, flight.PlannedDestairport); // didn't find the pilot if (_flight == null) { await db.AddAsync(flight); await db.SaveChangesAsync(); Log.Information($"Added Flight: {flight} to DB"); } else { // log.Info($"Flight found in DB: {_flight.ToString()}"); // DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_flight.TimeLogon); // DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(flight.TimeLogon); if (LogonTimeIsMoreRecent(_flight.TimeLogon, flight.TimeLogon)) { await db.AddAsync(flight); await db.SaveChangesAsync(); Log.Information($"Added Flight: {flight} to DB"); } else { _flight.Update(flight); db.Update(_flight); await db.SaveChangesAsync(); Log.Information($"Updated Flight: {flight} in DB"); } } } }