Example #1
0
        /// <summary>
        /// Obtiene las estaciones para una linea de subte
        /// </summary>
        /// <param name="lineId"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Domain.Dtos.Stop> > GetStopsByLineId(string lineId)
        {
            try
            {
                SubwayApiResponse <ForecastGtfsHeader, Integration.Entities.ForecastGtfs> response = await this._subwayApi.GetForecastGtfs(_clientId, _clientSecret);

                var route = response.Entity.Where(entity => entity.Line.RouteId == lineId).FirstOrDefault();
                if (route != null)
                {
                    return(route.Line.Stops.Select(stop => new Domain.Dtos.Stop {
                        Id = stop.StopId, Description = stop.StopName
                    }));
                }
                else
                {
                    throw new Exception("La linea que se desea consultar no existe.");
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Obtiene las alertas actuales del servicio y persiste en BD las que no existan para el día de hoy
        /// </summary>
        /// <returns></returns>
        public async Task <Domain.Dtos.ServiceAlert> GetServiceAlerts()
        {
            try
            {
                SubwayApiResponse <ServiceAlertsHeader, Integration.Entities.ServiceAlert> response = await this._subwayApi.GetServiceAlerts(_clientId, _clientSecret);

                Domain.Dtos.ServiceAlert serviceAlertResponse = _mapper.Map <Domain.Dtos.ServiceAlert>(response);
                await PersistServiceAlerts(serviceAlertResponse);

                return(serviceAlertResponse);
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Obtiene todas las lineas de subte
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <Domain.Dtos.Line> > GetSubwayLines()
        {
            try
            {
                SubwayApiResponse <ForecastGtfsHeader, Integration.Entities.ForecastGtfs> response = await this._subwayApi.GetForecastGtfs(_clientId, _clientSecret);

                return(response.Entity.Select(entity => entity.Line.RouteId).Distinct().Select(routeId => new Domain.Dtos.Line {
                    Id = routeId
                }));
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lineId"></param>
        /// <param name="stopId"></param>
        /// <param name="destinationStopId"></param>
        /// <returns></returns>
        public async Task <System.DateTime> GetNextArrivalToStop(string lineId, string stopId, string destinationStopId)
        {
            try
            {
                SubwayApiResponse <ForecastGtfsHeader, Integration.Entities.ForecastGtfs> response = await this._subwayApi.GetForecastGtfs(_clientId, _clientSecret);

                var routes = response.Entity.Where(entity => entity.Line.RouteId == lineId);

                if (routes != null && routes.Any())
                {
                    var route = routes.Where(route => route.Line.DirectionId == GetDirectionByStops(stopId, destinationStopId)).FirstOrDefault();

                    if (route != null)
                    {
                        if (route.Line.Stops.Select(stop => GetStopIdWithoutDirection(stop.StopId)).Contains(GetStopIdWithoutDirection(stopId)) &&
                            route.Line.Stops.Select(stop => GetStopIdWithoutDirection(stop.StopId)).Contains(GetStopIdWithoutDirection(destinationStopId)))
                        {
                            return(route.Line.Stops.Where(stop =>
                                                          GetStopIdWithoutDirection(stop.StopId) == GetStopIdWithoutDirection(stopId))
                                   .Select(stop => GetDateTimeFromUnixTime(stop.Arrival.Time)).FirstOrDefault());
                        }
                        else
                        {
                            throw new Exception("Las estaciones elegidas no pertenecen a la linea seleccionada.");
                        }
                    }
                    else
                    {
                        throw new Exception("Las estaciones seleccionadas no existen.");
                    }
                }
                else
                {
                    throw new Exception("La linea que se desea consultar no existe.");
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }