public void UpdateStation(DbStation stationDetails) { //code will reach when: 1. enter station, 2. exist station 3. add to waiting list Task.Run(() => { lock (key) { DbStation foundStation = GetStation(stationDetails.Id); Context.Entry(foundStation).Property(s => s.WaitingTime).CurrentValue = stationDetails.WaitingTime; ICollection <DbPlane> dbWaitingLine = new List <DbPlane>(); foreach (var plane in stationDetails.WaitingLine) { DbPlane dbPlane = this.DataHelper.GetOrCreatePlane(plane); dbWaitingLine.Add(dbPlane); } DbPlane foundPlane = null; if (stationDetails.CurrentPlane != null) { foundPlane = this.DataHelper.GetOrCreatePlane(stationDetails.CurrentPlane); } Context.Entry(foundStation).Collection(s => s.WaitingLine).CurrentValue = dbWaitingLine; Context.Entry(foundStation).Reference(s => s.CurrentPlane).CurrentValue = foundPlane; Context.SaveChanges(); } }); }
public DbPlane CreatePlane(DbPlane plane) { using (context = new AirportDbContext()) { DbPlane dbPlane = context.Planes.Add(plane); context.SaveChanges(); return(dbPlane); } }
internal static Plane ToDomainObject(this DbPlane dbPlane) { return(new Plane { Id = dbPlane.Id, FlightNumber = dbPlane.FlightNumber, EstimatedArrivalTime = ToDomainObject(dbPlane.EstimatedArrivalTime), EstimatedDepartureTime = ToDomainObject(dbPlane.EstimatedDepartureTime), TimeToExecution = dbPlane.TimeToExecution }); }
public Plane CreatePlane(Plane plane) { try { DbPlane dbPlane = Task.Run(() => _repository.CreatePlane(plane.ToDataEntity())).Result; Planes.Add(plane); return(plane); } catch (Exception) { throw; } }
internal static Plane ToDomainObject(this DbPlane dbPlane) { if (dbPlane != null) { return(new Plane { FlightNumber = dbPlane.FlightNumber, EstimatedArrivalTime = ToDomainObject(dbPlane.EstimatedArrivalTime), EstimatedDepartureTime = ToDomainObject(dbPlane.EstimatedDepartureTime), IsLanded = dbPlane.IsLanded }); } return(null); }
public DbPlane GetOrCreatePlane(DbPlane planeDetails) { DbPlane databasePlane = GetPlane(planeDetails.FlightNumber); if (databasePlane == null) //if plane does not exist in database, create a new one and return it. { dataContext.Planes.Add(planeDetails); dataContext.SaveChanges(); databasePlane = GetPlane(planeDetails.FlightNumber); } return(databasePlane); }
public async Task <DbPlane> GetOrCreatePlaneAsync(DbPlane planeDetails) { DbPlane databasePlane = await GetPlaneAsync(planeDetails.FlightNumber); if (databasePlane == null) //if plane does not exist in database, create a new one and return it. { dataContext.Planes.Add(planeDetails); await dataContext.SaveChangesAsync(); databasePlane = await GetPlaneAsync(databasePlane.FlightNumber); } return(databasePlane); }
public async Task CreatePlane(Plane plane) { try { DbPlane dbPlane = Task.Run(() => _repository.CreatePlane(plane.ToDataEntity())).Result; plane.Id = dbPlane.Id; Planes.Add(plane); await Task.Run(() => scheduleManager.CreateArrival(plane.EstimatedArrivalTime)); await Task.Run(() => scheduleManager.CreateDeparture(plane.EstimatedDepartureTime)); } catch (Exception) { throw; } }
public Plane ConvertPlane(DbPlane dbPlane) { if (dbPlane != null) { return(new Plane() { Id = dbPlane.Id, AirplaneType = dbPlane.AirplaneType, Color = Color.FromArgb(dbPlane.ColorARGB), Country = dbPlane.Country, FlightNumber = dbPlane.FlightNumber, PassangersCount = dbPlane.PassangersCount, Route = ConvertRoute(dbPlane.Route), }); } else { return(null); } }
public async Task AddLog(Station commonStation, StationChangedEventArgs args) { using (var context = new DataContext()) { DbStation station = context.Stations.First(station => station.Id == commonStation.Id); DbPlane plane = context.Planes.FirstOrDefault(plane => plane.FlightNumber == args.Plane.FlightNumber); if (plane != null) { PlaneLog log = new PlaneLog() { Plane = plane, Station = station, Time = args.EventTime, PlaneAction = args.PlaneAction }; context.PlanesLog.Add(log); await context.SaveChangesAsync(); } } }
public void TestCreateNewDBPlane() { mockRepo.LoadHistory(); int i = 5; DbArrival dbArrival = new DbArrival() { EstimatedArrivalTime = DateTime.Now.AddMinutes(1), Id = i }; DbDeparture dbDeparture = new DbDeparture() { EstimatedDepartureTime = DateTime.Now.AddMinutes(2), Id = i }; DbPlane dbPlane = new DbPlane() { FlightNumber = "mockDbPlane", EstimatedArrivalTime = dbArrival, EstimatedDepartureTime = dbDeparture, IsLanded = false }; var testDbPlane = mockRepo.CreatePlane(dbPlane); Assert.IsNotNull(testDbPlane); Assert.IsTrue(testDbPlane.EstimatedArrivalTime.EstimatedArrivalTime >= DateTime.Now); Assert.IsTrue(testDbPlane.EstimatedDepartureTime.EstimatedDepartureTime >= DateTime.Now); }
protected override void Seed(AirportDbContext context) { var arrival1 = new DbArrival { Id = 1, EstimatedArrivalTime = DateTime.Now.AddMinutes(2) }; var arrival2 = new DbArrival { Id = 2, EstimatedArrivalTime = DateTime.Now.AddMinutes(4) }; var arrival3 = new DbArrival { Id = 3, EstimatedArrivalTime = DateTime.Now.AddMinutes(3) }; var arrival4 = new DbArrival { Id = 4, EstimatedArrivalTime = DateTime.Now.AddMinutes(5) }; var departure1 = new DbDeparture { Id = 1, EstimatedDepartureTime = DateTime.Now.AddMinutes(7) }; var departure2 = new DbDeparture { Id = 2, EstimatedDepartureTime = DateTime.Now.AddMinutes(5) }; var departure3 = new DbDeparture { Id = 3, EstimatedDepartureTime = DateTime.Now.AddMinutes(5) }; var departure4 = new DbDeparture { Id = 4, EstimatedDepartureTime = DateTime.Now.AddMinutes(7) }; var plane1 = new DbPlane { FlightNumber = "TST007", EstimatedArrivalTime = arrival1, EstimatedDepartureTime = departure1 }; var plane2 = new DbPlane { FlightNumber = "TMP101", EstimatedArrivalTime = arrival2, EstimatedDepartureTime = departure2 }; var plane3 = new DbPlane { FlightNumber = "LST404", EstimatedArrivalTime = arrival3, EstimatedDepartureTime = departure3 }; var plane4 = new DbPlane { FlightNumber = "ERR302", EstimatedArrivalTime = arrival4, EstimatedDepartureTime = departure4 }; var station1 = new DbStation { Id = 1 }; var station2 = new DbStation { Id = 2 }; var station3 = new DbStation { Id = 3 }; var station4 = new DbStation { Id = 4 }; var station5 = new DbStation { Id = 5, }; var station6 = new DbStation { Id = 6 }; var station7 = new DbStation { Id = 7 }; var station8 = new DbStation { Id = 8, }; context.Stations.Add(station1); context.Stations.Add(station2); context.Stations.Add(station3); context.Stations.Add(station4); context.Stations.Add(station5); context.Stations.Add(station6); context.Stations.Add(station7); context.Stations.Add(station8); context.Departures.Add(departure1); context.Departures.Add(departure1); context.Departures.Add(departure3); context.Departures.Add(departure4); context.Arrivals.Add(arrival1); context.Arrivals.Add(arrival2); context.Arrivals.Add(arrival3); context.Arrivals.Add(arrival4); context.Planes.Add(plane1); context.Planes.Add(plane2); context.Planes.Add(plane3); context.Planes.Add(plane4); context.SaveChanges(); }
public async void AddPlane(DbPlane plane) { this.Context.Planes.Add(plane); await this.Context.SaveChangesAsync(); }
public async Task LoadHistory() { var arrival1 = new DbArrival { Id = 1, EstimatedArrivalTime = DateTime.Now.AddMinutes(1) }; var arrival2 = new DbArrival { Id = 2, EstimatedArrivalTime = DateTime.Now.AddMinutes(1) }; var arrival3 = new DbArrival { Id = 3, EstimatedArrivalTime = DateTime.Now.AddMinutes(2) }; var arrival4 = new DbArrival { Id = 4, EstimatedArrivalTime = DateTime.Now.AddMinutes(2) }; DbArrivals = new List <DbArrival>() { arrival1, arrival2, arrival3, arrival4 }; var departure1 = new DbDeparture { Id = 1, EstimatedDepartureTime = DateTime.Now.AddMinutes(2) }; var departure2 = new DbDeparture { Id = 2, EstimatedDepartureTime = DateTime.Now.AddMinutes(2) }; var departure3 = new DbDeparture { Id = 3, EstimatedDepartureTime = DateTime.Now.AddMinutes(3) }; var departure4 = new DbDeparture { Id = 4, EstimatedDepartureTime = DateTime.Now.AddMinutes(3) }; DbDepartures = new List <DbDeparture>() { departure1, departure2, departure3, departure4 }; var plane1 = new DbPlane { FlightNumber = "TST007", EstimatedArrivalTime = arrival1, EstimatedDepartureTime = departure1 }; var plane2 = new DbPlane { FlightNumber = "TMP101", EstimatedArrivalTime = arrival2, EstimatedDepartureTime = departure2 }; var plane3 = new DbPlane { FlightNumber = "LST404", EstimatedArrivalTime = arrival3, EstimatedDepartureTime = departure3 }; var plane4 = new DbPlane { FlightNumber = "ERR302", EstimatedArrivalTime = arrival4, EstimatedDepartureTime = departure4 }; DbPlanes = new List <DbPlane>() { plane1, plane2, plane3, plane4 }; var station1 = new DbStation { Id = 1 }; var station2 = new DbStation { Id = 2 }; var station3 = new DbStation { Id = 3 }; var station4 = new DbStation { Id = 4 }; var station5 = new DbStation { Id = 5, }; var station6 = new DbStation { Id = 6 }; var station7 = new DbStation { Id = 7 }; var station8 = new DbStation { Id = 8, }; DbStations = new DbStation[8] { station1, station2, station3, station4, station5, station6, station7, station8 }; }
public DbPlane CreatePlane(DbPlane plane) { DbPlanes.Append(plane); return(plane); }