public bool TryGetTrainX(string query, out TrainInfo trainInfo)
 {
     trainInfo = null;
     bool validEntity = false;
     string trainCode = CleanInputTextToNumbers(query.ToLower());
     validEntity = IsValidEntity(trainDict, trainCode);
     if (validEntity)
     {
         trainInfo = new TrainInfo();
         trainInfo.Name = trainDict[trainCode];
         trainInfo.Number = trainCode;
     }
     return validEntity;
 }
 //file contians 3 words
 public Dictionary<string, TrainInfo> ConvertTrainTsvToTrainDictionary(String tsvFilePath)
 {
     StreamReader reader = ReadFile(tsvFilePath);
     string readLine;
     while ((readLine = reader.ReadLine()) != null)
     {
         string[] a = readLine.Split('\t');
         TrainInfo trainInfo = new TrainInfo(a[2], a[1]);
         TrainMap[a[0]] = trainInfo;
     }
     reader.Close();
     return TrainMap;
 }
 public bool TryGetTrain(string query, out TrainInfo trainInfo)
 {
     trainInfo = null;
     bool validEntity = false;
     string trainCode = CleanInputTextToNumbers(query.ToLower());
     return TrainMap.TryGetValue(trainCode, out trainInfo);
 }
        public void UpdateUserProfile(TrainBookingState taskState, UserProfile userProfile)
        {
            // Update the passangers
            var knownPeopleList = userProfile.KnownPeopleList;

            if (knownPeopleList == null)
            {
                knownPeopleList = new List<Person>();
            }

            foreach (var passenger in taskState.PassangerInfoList)
            {
                if (passenger.Name.Equals(userProfile.UserId))
                {
                    Person me = userProfile.MyProfile;
                    if (string.IsNullOrEmpty(me.ContactNumber))
                    {
                        me.ContactNumber = taskState.PhoneNumber;
                    }
                    me.Gender = passenger.Gender;
                    me.DoB = DateTime.Now.AddYears(-(int) passenger.Age);
                }
                else
                {
                    Person person =
                        knownPeopleList.FirstOrDefault(
                            x => x.Name.Equals(passenger.Name, StringComparison.OrdinalIgnoreCase));
                    if (person == null)
                    {
                        person = new Person();
                    }

                    // TODO: do we need every time?
                    person.Name = passenger.Name;
                    person.Gender = passenger.Gender;
                    person.DoB = DateTime.Now.AddYears(-(int) passenger.Age);
                    person.Relation = passenger.Relation;
                    person.BerthChoice = passenger.BerthChoice;
                }
            }

            var preferredTrips = userProfile.PreferredTrips;
            if (preferredTrips == null)
            {
                preferredTrips = new Dictionary<string, List<TravelDestination>>();
                userProfile.PreferredTrips = preferredTrips;
            }

            List<TravelDestination> destinationList;
            string src = taskState.Source.Code;
            string dest = taskState.Destination.Code;
            if (!preferredTrips.TryGetValue(src, out destinationList))
            {
                destinationList = new List<TravelDestination>();
                preferredTrips.Add(src, destinationList);
            }

            TravelDestination destination = destinationList.FirstOrDefault(x => x.Code.Equals(dest));
            if (destination == null)
            {
                destination = new TravelDestination();
                destination.PreferredTrainList = new List<TrainInfo>();
                destination.Code = dest;
                destinationList.Add(destination);
            }

            TrainInfo trainInfo =
                destination.PreferredTrainList.FirstOrDefault(x => x.Number == taskState.TrainInfo.Number);

            if (trainInfo == null)
            {
                trainInfo = new TrainInfo();
                trainInfo.Number = taskState.TrainInfo.Number;
                trainInfo.Name = taskState.TrainInfo.Name;
                destination.PreferredTrainList.Add(trainInfo);
            }
        }