private async Task <SkillResponse> CreateResponseForDepartureByTypeRequestAsync(IntentRequest intentRequest, TransportationMean type)
        {
            logger.LogTrace($"Enter {nameof(CreateResponseForDepartureByTypeRequestAsync)}");

            var originStopName = intentRequest.TryGetSlotValue("originStopName");

            if (originStopName == null)
            {
                logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} (no slot value for {nameof(originStopName)})");
                return(CreatePlainTextResponse(Responses.NoSlotValueFor("die Abfahrtshaltestelle")));
            }

            var originStop = await FindStopByNameAsync(originStopName);

            if (originStop == null)
            {
                logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} (stop not found)");
                return(CreateStopNotFoundResponse(originStopName));
            }

            var finalDestinationStopName = intentRequest.TryGetSlotValue("finalDestinationStopName");

            if (finalDestinationStopName == null)
            {
                logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} (no slot value for {nameof(finalDestinationStopName)})");
                return(CreatePlainTextResponse(Responses.NoSlotValueFor("die Endhaltestelle")));
            }

            logger.LogDebug($"Next{type}DepartureFromStop: originStopName={originStopName}, finalDestinationStopName={finalDestinationStopName}");

            var departures = await departuresService.GetDeparturesForStopAsync(originStop, GetDeparturesForStopDefaultLimit);

            if (departures != null && departures.Count <= 0)
            {
                logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} (departures.Count <= 0)");
                return(CreatePlainTextResponse(Responses.NoDepartuesFoundForCriteriaText));
            }

            var filteredDepartures = departures
                                     .FilterByFinalDestination(finalDestinationStopName)
                                     .FilterByType(type)
                                     .ToList();

            if (filteredDepartures.Count <= 0)
            {
                logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} (filteredDepartures.Count <= 0)");
                return(CreatePlainTextResponse(Responses.NoDepartuesFoundForCriteriaText));
            }
            logger.LogTrace($"Exit {nameof(CreateResponseForDepartureByTypeRequestAsync)} [ok]");
            return(CreatePlainTextResponse(Responses.NextDepartureText(originStop, filteredDepartures[0])));
        }
Exemple #2
0
 internal static IEnumerable <Departure> FilterByType(this IEnumerable <Departure> departures, TransportationMean type)
 {
     return(departures.Where(d => d.Line.Type == type));
 }