Esempio n. 1
0
        public async Task <IActionResult> GetStationsDictionary()
        {
            try
            {
                GetStationsInforResponse stationsInfo = await _rail.GetStationsInfor(Enum.GetValues(typeof(E_Station)).Cast <E_Station>());

                Dictionary <int, string> res = stationsInfo.Data.ToDictionary(x => int.Parse(x.StationCode), y => y.Hebrew.StationName);
                return(Ok(res));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, $"Failed GetStationsDictionary()");
                return(StatusCode(500, ex));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> GetStationData(int id)
        {
            try
            {
                E_Station station = (E_Station)id;
                GetStationsInforResponse stationInfo = await _rail.GetStationsInfor(station);

                StationData stationData = new StationData(stationInfo.Data.FirstOrDefault(x => x.StationCode == id.ToString()), E_Language.Hebrew);
                return(Ok(stationData));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, $"Failed GetStationData({id})");
                return(StatusCode(500, ex));
            }
        }
Esempio n. 3
0
        public async Task <GetStationsInforResponse> GetStationsInfor(IEnumerable <E_Station> stations)
        {
            string     parameters = string.Join('&', stations.Select(x => $"stations={(int)x}"));
            UriBuilder ub         = new UriBuilder()
            {
                Path  = "apiinfo/api/infor/GetStationsInfor",
                Query = parameters
            };
            string     uri    = ub.Uri.PathAndQuery;
            HttpClient client = _clientFactory.CreateClient("RailApi");

            using (HttpResponseMessage response = await client.GetAsync(uri))
            {
                response.EnsureSuccessStatusCode();
                GetStationsInforResponse result = await response.Content.ReadAsAsync <GetStationsInforResponse>();

                return(result);
            }
        }
Esempio n. 4
0
        public StaticStationsRepository(IRail rail)
        {
            _rail = rail;
            GetStationsInforResponse stationsInfo = _rail.GetStationsInfor(Enum.GetValues(typeof(E_Station)).Cast <E_Station>()).Result;
            IEnumerable <GetStationsInforResponseData> stations = stationsInfo.Data.OrderBy(x => x.Hebrew.StationName);

            _stations = new List <StationLightData>();
            foreach (GetStationsInforResponseData s in stations)
            {
                StationLightData lightData = new StationLightData()
                {
                    Station   = (E_Station)int.Parse(s.StationCode),
                    Name      = s.Hebrew.StationName,
                    Latitude  = s.General.Lat,
                    Longitude = s.General.Long
                };
                _stations.Add(lightData);
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Station(int id)
        {
            try
            {
                E_Station station = (E_Station)id;
                GetStationsInforResponse stationInfo = await _rail.GetStationsInfor(station);

                StationData stationData = new StationData(stationInfo.Data.FirstOrDefault(x => x.StationCode == id.ToString()), E_Language.Hebrew);
                ViewBag.GoogleMapsUrl = _google.GetGoogleMapsUrl(stationData);
                return(PartialView("_Station", stationData));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, $"Failed Station({id})");
                return(PartialView("Error", new ErrorViewModel()
                {
                    Exception = ex
                }));
            }
        }
Esempio n. 6
0
        public async Task <GetStationsInforResponse> GetStationsInfor(E_Station station)
        {
            NameValueCollection parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["stations"] = ((int)station).ToString();
            UriBuilder ub = new UriBuilder()
            {
                Path  = "apiinfo/api/infor/GetStationsInfor",
                Query = HttpUtility.UrlDecode(parameters.ToString())
            };
            string     uri    = ub.Uri.PathAndQuery;
            HttpClient client = _clientFactory.CreateClient("RailApi");

            using (HttpResponseMessage response = await client.GetAsync(uri))
            {
                response.EnsureSuccessStatusCode();
                GetStationsInforResponse result = await response.Content.ReadAsAsync <GetStationsInforResponse>();

                return(result);
            }
        }