Exemplo n.º 1
0
        public StationModel GetTrainAtNearestTime(string station = "", string datetime = "")
        {
            List <StationModel> all    = GetAllStations();
            StationModel        result = new StationModel();

            if (!string.IsNullOrEmpty(station))
            {
                all = all.Where(c => c.name.ToLower().Contains(station)).ToList();
            }

            DateTime startTime = DateTime.Now;

            if (!string.IsNullOrEmpty(datetime))
            {
                startTime = Convert.ToDateTime(datetime);
            }

            StationList     stationList  = new StationList();
            List <DateTime> lisburnTimes = stationList.GetTimeTableForStation("Lisburn");
            List <DateTime> botanicTime  = stationList.GetTimeTableForStation("Botanic");

            DateTime lisburnNearest = GetNearestTimeValue(startTime, lisburnTimes);
            DateTime botanicNearest = GetNearestTimeValue(startTime, botanicTime);

            if (lisburnNearest < botanicNearest || station.ToLower().Contains("lisburn"))
            {
                result = GetStationByName("Lisburn");
                result.scheduledTime = lisburnNearest;
                DateTime expected = GetExpectedTrainTime("Lisburn");

                if (expected != DateTime.MinValue)
                {
                    result.expectedTime = expected;
                }
                else
                {
                    result.expectedTime = result.scheduledTime;
                }

                return(result);
            }
            else
            {
                result = GetStationByName("Botanic");
                result.scheduledTime = botanicNearest;
                DateTime expected = GetExpectedTrainTime("Botanic");

                if (expected != DateTime.MinValue)
                {
                    result.expectedTime = expected;
                }
                else
                {
                    result.expectedTime = result.scheduledTime;
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        public List <StationModel> GetAllStations()
        {
            StationList list = new StationList();

            return(list.stations);
        }