/// <summary> /// Get all line trip of spesific station /// build each one with the arrival time to this station /// </summary> /// <param name="station"></param> /// <returns></returns> public IEnumerable <BO.LineTrip> GetAllLineTripsByStation(BO.Station station) { return(from line in station.LinesPassBy from lineTrip in GetAllLineTrips() where lineTrip.LineId == line.Id let lineTripRes = SetArrivalTimeToStation(station, lineTrip) orderby lineTripRes.ArrivalTimeToStation select lineTripRes); }
/// <summary> /// Remove station from the database /// </summary> /// <param name="station"></param> public void RemoveStation(BO.Station station) { var stationDo = station.CopyPropertiesToNew(typeof(DO.Station)) as DO.Station; try { dl.RemoveStation(stationDo); } catch (DO.BadStationException ex) { throw new BO.BadStationException(station.Code, ex.Message); } }
BO.LineTrip SetArrivalTimeToStation(BO.Station station, BO.LineTrip lineTrip) { TimeSpan arrivalTime = TimeSpan.Zero; // Summarize the time of the line until it reaches the given station foreach (var lineStation in GetAllLineStationsByLineID(lineTrip.LineId)) { arrivalTime += lineStation.TimeFromNext; if (lineStation.Station == station.Code) { break; } } lineTrip.ArrivalTimeToStation = lineTrip.CurrentTimeToStation = arrivalTime + lineTrip.StartAt; return(lineTrip); }
/// <summary> /// Get a single station from the database /// build the station with the line that pass in her and the adjacent stations to her /// </summary> /// <param name="code"></param> /// <returns></returns> public BO.Station GetStation(int code) { var stationBo = new BO.Station(); try { var stationDo = dl.GetStation(code); stationDo.CopyPropertiesTo(stationBo); stationBo.LinesPassBy = GetAllLinePassByStation(code); stationBo.MyAdjacentStations = GetAllAdjacentStationsOf(code); } catch (DO.BadStationException ex) { throw new BO.BadStationException(code, ex.Message); } return(stationBo); }
/// <summary> /// Add new station to the database /// </summary> /// <param name="station"></param> public void AddStation(BO.Station station) { var stationDo = station.CopyPropertiesToNew(typeof(DO.Station)) as DO.Station; try { if (!validLatLon(stationDo.Latitude, stationDo.Longitude)) { throw new BO.BadStationException(stationDo.Code, "The location entered is outside the earth"); } dl.AddStation(stationDo); } catch (DO.BadStationException ex) { throw new BO.BadStationException(station.Code, ex.Message); } }