示例#1
0
        public async Task GetYoubikeAPI()
        {
            try
            {
                string responseContent = await _httpClientHelpers.GetAPI(YoubikeRequestUrl);

                if (!string.IsNullOrWhiteSpace(responseContent))
                {
                    var jObject      = JObject.Parse(responseContent);
                    var contentValue = jObject["retVal"].Children().Values();

                    var stationList = _dBHelpers.GetYouBikeStationList().ToDictionary(n => n.SNO, n => n.SNA);

                    foreach (var item in contentValue)
                    {
                        //已停用的站點不再更新紀錄
                        if (item.Value <int>("act") == 1)
                        {
                            if (!stationList.ContainsKey(item.Value <string>("sno")))
                            {
                                _dBHelpers.AddYouBikeStation(new YouBikeStationModel()
                                {
                                    SNO     = item.Value <string>("sno"),
                                    SNA     = item.Value <string>("sna"),
                                    TOT     = item.Value <int>("tot"),
                                    SAREA   = item.Value <string>("sarea"),
                                    LAT     = item.Value <string>("lat"),
                                    LNG     = item.Value <string>("lng"),
                                    AR      = item.Value <string>("ar"),
                                    SAREAEN = item.Value <string>("sareaen"),
                                    SNAEN   = item.Value <string>("snaen"),
                                    AREN    = item.Value <string>("aren"),
                                    ACT     = item.Value <int>("act")
                                });
                            }

                            DateTime _mday;
                            if (DateTime.TryParseExact(item.Value <string>("mday"), "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None, out _mday) &&
                                _mday.CompareTo(DateTime.Now.AddHours(-1)) >= 0)
                            {
                                _dBHelpers.AddYouBikeLog(new YouBikeLogModel()
                                {
                                    LOGID          = string.Concat(item.Value <string>("sno"), item.Value <string>("mday")),
                                    SNO            = item.Value <string>("sno"),
                                    SBI            = item.Value <int>("sbi"),
                                    MDAY           = item.Value <string>("mday"),
                                    BEMP           = item.Value <int>("bemp"),
                                    UPDATEDATETIME = DateTime.Now
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }
        public IActionResult SearchYoubikeLog()
        {
            YoubikeLogFinderModel model = new YoubikeLogFinderModel();

            model.stationList = _dBHelpers.GetYouBikeStationList()
                                .Select(n => new SelectListItem()
            {
                Text = n.SNA, Value = n.SNO
            }).ToList();

            model.regionList = _dBHelpers.GetRegionList().Select(n => new SelectListItem()
            {
                Text = n.AREANAME, Value = n.AREANAME
            }).ToList();

            return(View(model));
        }