internal static Station ToDomainObject(this DbStation dbStation) { if (dbStation != null) { if (dbStation.NextStationsIds != null) { return(new Station { Id = dbStation.Id, NextStationsIds = dbStation.NextStationsIds, CurrentPlane = ToDomainObject(dbStation.CurrentPlane) }); } else { return(new Station { Id = dbStation.Id, NextStationsIds = null, CurrentPlane = ToDomainObject(dbStation.CurrentPlane) }); } } return(null); }
public ActionResult AddStation(AdminModel modelIn) { var lineIn = _lineBll.GetLineById(modelIn.Line.Id); var stationInDb = new DbStation() { StationName = modelIn.Station.StationName, NumberOnLine = modelIn.Station.NumberOnLine, TrainLine = lineIn }; var stationIn = new RepositoryModelStation() { StationName = modelIn.Station.StationName, NumberOnLine = modelIn.Station.NumberOnLine, TrainLine = lineIn }; _stationBll.AddStation(stationIn); lineIn.Stations.Add(stationInDb); _lineBll.UpdateLine(lineIn); ViewBag.line = lineIn; var model = new AdminModel() { Line = lineIn }; ViewBag.line = lineIn; ViewBag.added = "true"; return(View("EditLine", model)); }
public List <DbStation> GetStationsFromNames(string fromStation, string toStation) { if (fromStation.Equals("")) { return(null); } if (toStation.Equals("")) { return(null); } var list = new List <DbStation>(); var dbStation = new DbStation() { Id = 1, NumberOnLine = 1, StationName = toStation }; var dbStation2 = new DbStation() { Id = 1, NumberOnLine = 1, StationName = fromStation }; list.Add(dbStation2); list.Add(dbStation); return(list); }
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 List <DbTrainLine> GetAllLines() { List <DbTrainLine> lines = new List <DbTrainLine>(); var list = new List <DbStation>(); var dbStation = new DbStation() { Id = 1, NumberOnLine = 1, StationName = "StasjonsNavn1" }; list.Add(dbStation); list.Add(dbStation); list.Add(dbStation); var line = new DbTrainLine() { Id = 123, Name = "test", Stations = list }; lines.Add(line); lines.Add(line); lines.Add(line); return(lines); }
public bool DeleteStation(int id) { DbStation station = _databaseContext.Stations.FirstOrDefault(r => r.Id == id); _databaseContext.Stations.Remove(station); _databaseContext.SaveChanges(); return(true); }
public void UpdateDatabase(object sender, StationChangedEventArgs args) { if (sender != null && args != null) { Station station = (Station)sender; DbStation dbStation = this.converterProvider.CommonToDb.ConvertStation(station); this.dataService.UpdateStation(dbStation); } }
public RepositoryModelStation DbToServiceStation(DbStation dbStation) { return(new RepositoryModelStation { Id = dbStation.Id, NumberOnLine = dbStation.NumberOnLine, StationName = dbStation.StationName, TrainLine = dbStation.TrainLine }); }
public DbStation UpdateStationById(int id, DbStation station) { DbStation original = DbStations.SingleOrDefault(s => s.Id == id); if (original != null) { original.CurrentPlane = station.CurrentPlane; original.NextStationsIds = station.NextStationsIds; original.TimeToExecution = station.TimeToExecution; } return(original); }
public bool AddStation(RepositoryModelStation station) { var dbStation = new DbStation() { StationName = station.StationName, TrainLine = null, NumberOnLine = 3254 }; _databaseContext.Add(dbStation); _databaseContext.SaveChanges(); return(true); }
public DbStation UpdateStationById(int id, DbStation station) { using (context = new AirportDbContext()) { DbStation original = context.Stations.SingleOrDefault(s => s.Id == id); if (original != null) { original.CurrentPlane = station.CurrentPlane; original.NextStationsIds = station.NextStationsIds; original.TimeToExecution = station.TimeToExecution; } context.SaveChanges(); return(original); } }
public double GeneratePrice(DbStation fromStation, DbStation toStation, DbPassengerType passengerType) { var start = fromStation.NumberOnLine; var end = toStation.NumberOnLine; var price = 0.0; if (start > end) { price = (start - end) * passengerType.PriceMultiplier; } else { price = (end - start) * passengerType.PriceMultiplier; } return(price); }
internal static Station ToDomainObject(this DbStation dbStation) { List <Station> stations = new List <Station>(); foreach (var item in dbStation.NextStations) { stations.Add(ToDomainObject(item)); } return(new Station { Id = dbStation.Id, NextStations = stations, CurrentPlane = ToDomainObject(dbStation.CurrentPlane), IsLandingStation = dbStation.IsLandingStation, IsTakeoffStation = dbStation.IsTakeoffStation }); }
private Station ConvertStation(DbStation station) { var commonStation = new Station() { Id = station.Id, StationName = station.StationName, StationNumber = station.StationNumber, CurrentPlane = ConvertPlane(station.CurrentPlane), WaitingTime = station.WaitingTime, }; if (station.WaitingLine != null) { commonStation.WaitingLine = new ConcurrentQueue <Plane>(ConvertPlanes(station.WaitingLine)); } return(commonStation); }
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(); } } }
private static List <DbStation> SeedStations(DatabaseContext dbContext, string stations) { string[] separator = { ", " }; var stationNames = stations.Split(separator, StringSplitOptions.RemoveEmptyEntries); var numberOnLine = 1; List <DbStation> stationList = new List <DbStation>(); foreach (var stationName in stationNames) { var stationFromFile = new DbStation { StationName = stationName, NumberOnLine = numberOnLine }; dbContext.Add(stationFromFile); stationList.Add(stationFromFile); numberOnLine++; } dbContext.SaveChanges(); return(stationList); }
public DbTrainLine GetLineById(int id) { var list = new List <DbStation>(); var dbStation = new DbStation() { Id = 1, NumberOnLine = 1, StationName = "StasjonsNavn1" }; list.Add(dbStation); list.Add(dbStation); list.Add(dbStation); var line = new DbTrainLine() { Id = 123, Name = "test", Stations = list }; return(line); }
public List <DbStation> GetStationsFromNames(string fromStation, string toStation) { var stations = new List <DbStation>(); DbStation fromStationObject = null; DbStation toStationObject = null; foreach (var station in _databaseContext.Stations) { if (fromStation.Equals(station.StationName)) { fromStationObject = station; } if (toStation.Equals(station.StationName)) { toStationObject = station; } } stations.Add(fromStationObject); stations.Add(toStationObject); return(stations); }
public ActionResult EditStation(AdminModel modelIn) { var lineIn = _lineBll.GetLineById(modelIn.Line.Id); var stationInDb = new DbStation() { Id = modelIn.Station.Id, StationName = modelIn.Station.StationName, NumberOnLine = modelIn.Station.NumberOnLine, TrainLine = lineIn }; var stationIn = new RepositoryModelStation() { Id = modelIn.Station.Id, StationName = modelIn.Station.StationName, NumberOnLine = modelIn.Station.NumberOnLine, TrainLine = lineIn }; _stationBll.UpdateStation(stationIn.Id, stationIn); for (int i = 0; i < lineIn.Stations.Count; i++) { if (lineIn.Stations[i].Id == stationInDb.Id) { lineIn.Stations[i].StationName = stationInDb.StationName; lineIn.Stations[i].NumberOnLine = stationInDb.NumberOnLine; } } _lineBll.UpdateLine(lineIn); ViewBag.line = lineIn; return(View()); }
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 }; }
private double GeneratePrice(DbStation fromStation, DbStation toStation, DbPassengerType passengerType) { return(_ticketRepository.GeneratePrice(fromStation, toStation, passengerType)); }
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(); }