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 { throw new ArgumentException("BL failed to add station because : Duplicate Stations"); } }
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); }
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 }); } } }
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 = lineBo.TotalDistance * 0.0012 * 0.5; return(lineBo); }