BO.BusLine BusLineDoBoAdapter(DO.BusLine lineDo) { BO.BusLine lineBo = new BO.BusLine(); lineDo.CopyPropertiesTo(lineBo); DO.BusLine busLine = dl.GetLine(lineBo.BusLineNumber, AreasAdapter(lineBo.Area)); List <int> request = (from station in dl.GetAllLineStationsBy(s => s.LineId == busLine.Id) orderby station.RankInLine select station.StationKey).ToList(); lineBo.AllStationsOfLine = request; for (int i = 0; i < lineBo.AllStationsOfLine.Count() - 1; i++) { DO.BusStation station1 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i))); DO.BusStation station2 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i + 1))); lineBo.TotalDistance += dl.GetFollowingStations(station1, station2).Distance; lineBo.TotalTime += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } lineBo.TotalDistance = Math.Round(lineBo.TotalDistance /= 1000); lineBo.AllLineTripsOfLine = (from lt in GetAllLineTripsBy(t => t.LineId == busLine.Id) orderby lt.StartTimeRange select lt).ToList(); return(lineBo); }
public BO.BusStation BusStationDoBoAdapter(DO.BusStation stationDo) { BO.BusStation stationBo = new BO.BusStation(); stationDo.CopyPropertiesTo(stationBo); List <int> test = (from line in dl.GetAllLineStationsBy(s => s.StationKey == stationBo.BusStationKey) select line.LineId).ToList(); stationBo.LinesThatPass = test; return(stationBo); }
public void AddStation(BO.BusStation newStation) { DO.BusStation stationToAdd = BusStationBoDoAdapter(newStation); try { dl.AddStation(stationToAdd); } catch (DO.DuplicateStationException ex) { throw new BO.DuplicateStationException("You can't add this station because it already exists", ex); } }
public void AddBusLine(BO.BusLine newLine) { //1. Verify if all stations of list exists foreach (int item in newLine.AllStationsOfLine) { try { dl.GetStation(item); } catch (DO.InexistantStationException ex) { throw new BO.InexistantStationException("Please create station and then add it to line", ex); } } for (int i = 0; i < (newLine.AllStationsOfLine.Count() - 1); i++) { //2. Add FollowingStations if it's necessary DO.BusStation station1 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i)); DO.BusStation station2 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i + 1)); if (dl.GetFollowingStations(station1, station2) == null) { dl.AddFollowingStations(station1, station2); } newLine.TotalTime += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } dl.AddLine(BusLineBoDoAdapter(newLine));//add line to can then add lisStations with LineId (attributed in dl.AddLine) //3. Create corresponding line stations int lineId = dl.GetLine(newLine.BusLineNumber, AreasAdapter(newLine.Area)).Id; for (int i = 0; i < newLine.AllStationsOfLine.Count(); i++) { int stationKey = GetBusStation(newLine.AllStationsOfLine.ElementAt(i)).BusStationKey; if (GetLineStation(lineId, stationKey) == null) { AddLineStation(new BO.LineStation { LineId = lineId, StationKey = stationKey, RankInLine = i + 1 }); } } //4. Create corresponding trip line foreach (BO.LineTrip item in newLine.AllLineTripsOfLine) { item.LineId = lineId; AddLineTrip(item); } }
DO.BusStation BusStationBoDoAdapter(BO.BusStation stationBo) { DO.BusStation stationDo = new DO.BusStation(); stationBo.CopyPropertiesTo(stationDo); if (stationDo.Latitude == 0) { stationDo.Latitude = rndLat.NextDouble() + 31; } if (stationDo.Longitude == 0) { stationDo.Longitude = rndLong.NextDouble() + 34; } return(stationDo); }
internal TimeSpan DurationOfTravel(BO.BusLine line, int stationKey) { int rankOfStation = dl.GetLineStation(line.Id, stationKey).RankInLine; IEnumerable <DO.LineStation> stations = (from lineStat in dl.GetAllLineStationsBy(l => l.LineId == line.Id).ToList() where lineStat.RankInLine <= rankOfStation select lineStat).ToList(); TimeSpan travelDuration = new TimeSpan(); for (int i = 0; i < stations.Count() - 1; i++) { DO.BusStation station1 = BusStationBoDoAdapter(GetBusStation(stations.ElementAt(i).StationKey)); DO.BusStation station2 = BusStationBoDoAdapter(GetBusStation(stations.ElementAt(i + 1).StationKey)); travelDuration += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } return(travelDuration); }