Пример #1
0
        public List<TrainModel> GetAllTrains()
        {
            var allTrainModels = new List<TrainModel>();

            foreach (var train in UrbanTrainDatabase.Trains)
            {
                var trainStatus = GetTrainStatus(train.TrainStatusId);

                var trainModel = new TrainModel
                {
                    TrainNO = train.TrainNO,
                    LineId = train.LineId,
                    LineTrainIsPlying = train.LineId,
                    NextTrainStop =train.NextStop,
                    LastTrainStop= train.LastStop,
                    TrainStatus = trainStatus,
                    MainTrainLink = new LinkModel
                    {
                        Href = "http://localhost:60013/api/Trains/" + train.TrainNO,
                        Rel = "Train " + train.TrainNO,
                        Method = "GET"
                    }

                };
                trainModel.CurrentLocation = GetTrainCurrentLocation(trainModel);
                allTrainModels.Add(trainModel);
            }
            return allTrainModels;
        }
Пример #2
0
        public string GetTrainCurrentLocation(TrainModel trainModel)
        {
            if (trainModel.TrainStatus == "Moving")
                {
                    return "Moving towards " + trainModel.NextTrainStop + " From " + trainModel.LastTrainStop;
                }

                else if (trainModel.TrainStatus == "Stopped at stop")
                {

                    return trainModel.LastTrainStop;
                }
                else
                {

                    return "Currently stopped between " + trainModel.NextTrainStop + " and " + trainModel.LastTrainStop;

                }
        }