/// <summary> /// Method to execute the task which is to create adaptive card attachment of the reservation indicated by the user and display it. /// </summary> /// <param name="stepContext"></param> /// <param name="cancellationToken"></param> /// <returns>NextAsync</returns> private async Task <DialogTurnResult> DisplayReservationAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { //Get ReservationStorage object. ReservationStorage rstorage = await _accessor.ReservationStorageAccessor.GetAsync(stepContext.Context, () => new ReservationStorage()); //Initialize reservation list and assign list of reservations stored in rstorage. IList <FlightInfo> reservations = rstorage.Reservations; //Get flight ID provided by the user and convert it to integer. int flightId = int.Parse(stepContext.Result as string); //Initialize reservationInfo variable. FlightInfo reservationInfo = new FlightInfo(); //This block tries to find suitable reservation ID in the list of reservations using Linq expression, if there is not any suitable reservation ID it caches the exception and assigns reservationInfo variable as null. try { var result = from r in reservations where r.ReservationId == flightId select r; reservationInfo = result.First(); } catch (Exception e) when(e.Message == "Sequence contains no elements") { reservationInfo = null; }; //This block decides if reservationInfo is not empty and there is any reservation to display. if (reservationInfo != null) { Attachment attachment = new Attachment(); // This block decides which adaptive card template should be used based on reservation details. if (reservationInfo.OneWayFlight && reservationInfo.Rental == null) { attachment = CreateReservationAttachement(@".\Resources\FlightDetailsOneWay.txt", reservationInfo.PassengerName, reservationInfo.FromAirport, reservationInfo.ToAirport, reservationInfo.StartDate, reservationInfo.TripClass, (reservationInfo.FlightCost.ToString() + " $"), reservationInfo.ReservationId.ToString()); } else if (!reservationInfo.OneWayFlight && reservationInfo.Rental == null) { attachment = CreateReservationAttachement(@".\Resources\FlightDetailsTwoWays.txt", reservationInfo.PassengerName, reservationInfo.FromAirport, reservationInfo.ToAirport, reservationInfo.StartDate, reservationInfo.TripClass, (reservationInfo.FlightCost.ToString() + " $"), reservationInfo.ReservationId.ToString(), reservationInfo.EndDate); } else if (reservationInfo.OneWayFlight && reservationInfo.Rental != null) { attachment = CreateCombinedAttachement(@".\Resources\FlightDetailsOneWayRental.txt", reservationInfo.PassengerName, reservationInfo.FromAirport, reservationInfo.ToAirport, reservationInfo.StartDate, reservationInfo.TripClass, (reservationInfo.FlightCost.ToString() + " $"), reservationInfo.ReservationId.ToString(), reservationInfo.Rental.RentalLength, reservationInfo.Rental.PassengersNumber, reservationInfo.Rental.ChildSeats, reservationInfo.Rental.CarClass, reservationInfo.Rental.RentalCost); } else if (!reservationInfo.OneWayFlight && reservationInfo.Rental != null) { attachment = CreateCombinedAttachement(@".\Resources\FlightDetailsTwoWaysRental.txt", reservationInfo.PassengerName, reservationInfo.FromAirport, reservationInfo.ToAirport, reservationInfo.StartDate, reservationInfo.TripClass, (reservationInfo.FlightCost.ToString() + " $"), reservationInfo.ReservationId.ToString(), reservationInfo.Rental.RentalLength, reservationInfo.Rental.PassengersNumber, reservationInfo.Rental.ChildSeats, reservationInfo.Rental.CarClass, reservationInfo.Rental.RentalCost, reservationInfo.EndDate); } ; //Initialize reply Activity. Activity reply = stepContext.Context.Activity.CreateReply(); //Add created attachment to the lift of attachments. reply.Attachments = new List <Attachment>() { attachment }; await stepContext.Context.SendActivityAsync(reply, cancellationToken : cancellationToken); //Add flight id provided by user to the stepContext.Values distionary. stepContext.Values["RequestID"] = flightId; } //Inform user that there is not any reservation to dispaly. else { await stepContext.Context.SendActivityAsync("There is not any reservation matching provided ID."); //Add default value of request id = 0 to the stepContext.Values distionary. stepContext.Values["RequestID"] = 0; } return(await stepContext.NextAsync()); }