public IHttpActionResult GetRouteDepartures(int routeType, int stopId, string routeId, int?max_results = null, int?direction_id = null)
        {
            var departuresApi      = new DeparturesApi(new PTVApi.Client.Configuration(new ApiClient("http://timetableapi.ptv.vic.gov.au", _devId, _apiKey)));
            var departuresResponse = departuresApi.DeparturesGetForStopAndRoute(routeType, stopId, routeId, directionId: direction_id, maxResults: max_results);
            var departures         = Mapper.Map <List <V3Departure>, List <RouteDepartureDto> >(departuresResponse.Departures);

            return(Ok(departures));
        }
        public IHttpActionResult GetDepaturesFromStop(int routeType, int stopId)
        {
            var departuresApi = new DeparturesApi(new PTVApi.Client.Configuration(new ApiClient("http://timetableapi.ptv.vic.gov.au", _devId, _apiKey)));
            var response      = departuresApi.DeparturesGetForStop(routeType, stopId, maxResults: 5);

            List <StopDepartureDto> departuresResponse = new List <StopDepartureDto>();
            var routesApi     = new RoutesApi(new PTVApi.Client.Configuration(new ApiClient("http://timetableapi.ptv.vic.gov.au", _devId, _apiKey)));
            var directionsApi = new DirectionsApi(new PTVApi.Client.Configuration(new ApiClient("http://timetableapi.ptv.vic.gov.au", _devId, _apiKey)));
            Dictionary <int, V3Route> routesDetail   = new Dictionary <int, V3Route>();
            Dictionary <int, string>  directionsName = new Dictionary <int, string>();

            foreach (V3Departure departure in response.Departures)
            {
                var detailedDeparture = Mapper.Map <V3Departure, StopDepartureDto>(departure);
                //Add Route Details to departure
                var     routeId = departure.RouteId.Value;
                V3Route route;
                if (!routesDetail.Keys.Contains(routeId))
                {
                    route = routesApi.RoutesRouteFromId(routeId).Route;
                    routesDetail.Add(routeId, route);
                }
                else
                {
                    route = routesDetail[routeId];
                }
                detailedDeparture.RouteName   = route.RouteName;
                detailedDeparture.RouteNumber = route.RouteNumber;
                detailedDeparture.RouteType   = route.RouteType.Value;

                //Add Directions Details to departure
                var    directionId = departure.DirectionId.Value;
                String directionName;
                if (!directionsName.Keys.Contains(directionId))
                {
                    var directionResponse = directionsApi.DirectionsForRoute(routeId);
                    directionName = directionResponse.Directions.Find(d => d.DirectionId == directionId).DirectionName;
                    directionsName.Add(directionId, directionName);
                }
                else
                {
                    directionName = directionsName[directionId];
                }
                detailedDeparture.DirectionName = directionName;

                departuresResponse.Add(detailedDeparture);
            }

            return(Ok(departuresResponse));
        }