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 void Update(VatsimClientPilot pilot) { this.Callsign = pilot.Callsign; this.Cid = pilot.Cid; this.Clienttype = pilot.Clienttype; this.Latitude = pilot.Latitude; this.Longitude = pilot.Longitude; this.Protrevision = pilot.Protrevision; this.Realname = pilot.Realname; this.Server = pilot.Server; this.TimeLastAtisReceived = pilot.TimeLastAtisReceived; this.TimeLogon = pilot.TimeLogon; }
public VatsimClientPilot GetVatsimClientPilotFromRecord() { VatsimClientPilot pilot = new VatsimClientPilot(); pilot.Callsign = this.Callsign; pilot.Cid = this.Cid; pilot.Clienttype = this.Clienttype; pilot.Latitude = this.Latitude; pilot.Longitude = this.Longitude; pilot.Realname = this.Realname; pilot.Protrevision = this.Protrevision; pilot.Server = this.Server; pilot.TimeLastAtisReceived = this.TimeLastAtisReceived; pilot.TimeLogon = this.TimeLogon; return(pilot); }