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); } }
public void AddBusLine(BO.BusLine newLine) { //1. Verify if all stations of list exists foreach (int item in newLine.AllStationsOfLine) { if (dl.GetStation(item) == null) { throw new ArgumentException("Bus Station " + item + " doesn't exist. Please create station and then" + " add it to line"); } } 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); } } dl.AddLine(BusLineBoDoAdapter(newLine)); //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 }); } } }