public TaskAnswer() { TaskType = TaskType.Train; TaskState = new TrainBookingState(); ChatWindow = new ChatWindow(); CurrentState = TaskStateCode.InitState; NextState = TaskStateCode.InitState; CurrentPassengerId = 1; CompletedPassengers = 0; TicketBookedState = BookedState.None; IsStateFinished = false; }
static void CreateSampleAnswer() { ChatItem item1 = new ChatItem(); item1.Id = "Cortana"; item1.ChatText = "Hi this is Cortana"; ChatItem item2 = new ChatItem(); item2.Id = "User"; item2.ChatText = "Hi this is User"; ChatItem item3 = new ChatItem(); item3.Id = "Cortana"; item3.ChatText = "Hi shall we complete the Task?"; ChatWindow chatWindow = new ChatWindow(); chatWindow.ChatList.Add(item1); chatWindow.ChatList.Add(item2); chatWindow.ChatList.Add(item3); TrainBookingState bookingState = new TrainBookingState(); bookingState.Source = new Station(); bookingState.Source.Name = "Hyderabad"; bookingState.Source.Code = "SC"; bookingState.Destination = new Station(); bookingState.Destination.Name = "Chennai Central"; bookingState.Destination.Code = "MAS"; bookingState.DateOfJourney = DateTime.Now.AddDays(10); bookingState.TrainInfo = new TrainInfo(); bookingState.TrainInfo.Name = "Chennai Express"; bookingState.TrainInfo.Number = "12604"; bookingState.CoachPreference = CoachType.SecondAC; bookingState.PhoneNumber = "1234567890"; bookingState.NumberOfPassangers = 4; PassangerInfo pas1 = new PassangerInfo(); pas1.Name = "BillGates"; pas1.Age = 50; pas1.Gender = Gender.Male; pas1.BerthChoice = BerthChoice.SideLower; PassangerInfo pas2 = new PassangerInfo(); pas2.Name = "Balmer"; pas2.Age = 49; pas2.Gender = Gender.Male; pas2.BerthChoice = BerthChoice.SideUpper; PassangerInfo pas3 = new PassangerInfo(); pas3.Name = "BillGates"; pas3.Age = 45; pas3.Gender = Gender.Male; pas3.BerthChoice = BerthChoice.Lower; bookingState.PassangerInfoList = new List<PassangerInfo>(); bookingState.PassangerInfoList.Add(pas1); bookingState.PassangerInfoList.Add(pas2); bookingState.PassangerInfoList.Add(pas3); TaskAnswer answer = new TaskAnswer(); answer.Title = "Book Train Ticket Task"; answer.TaskType = TaskType.Train; answer.ChatWindow = chatWindow; answer.TaskState = bookingState; string jsonString = JsonConvert.SerializeObject(answer); return; }
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); } }