Esempio n. 1
0
        /// <summary>
        /// 取得公車路線
        /// </summary>
        /// <returns></returns>
        public ActionResult GetRoute(string city, string keyword = "")
        {
            IBusRoute repos = DataFactory.BusRouteRepository();
            Dictionary <string, int> dicCity = new Dictionary <string, int>();

            for (int i = 0; i <= listCity.Count - 1; i++)
            {
                dicCity.Add(listCity[i], i + 1);
            }

            return(Content(JsonConvert.SerializeObject(repos.GetRoute(dicCity.ContainsKey(city)?dicCity[city]:1, keyword)), "application/json"));
        }
Esempio n. 2
0
        public IHttpActionResult GetRoute(string city, string keyword = "")
        {
            //Initial
            IHttpActionResult        responseResult;
            IBusRoute                repos   = DataFactory.BusRouteRepository();
            Dictionary <string, int> dicCity = new Dictionary <string, int>();

            for (int i = 0; i <= listCity.Count - 1; i++)
            {
                dicCity.Add(listCity[i], i + 1);
            }
            //序列化撈出來的資料
            var jsonSerialize = JsonConvert.SerializeObject(repos.GetRoute(dicCity.ContainsKey(city) ? dicCity[city] : 1, keyword));
            //做成JSON字串包裝到最後輸出
            StringContent       responseMsgString = new StringContent(jsonSerialize, System.Text.Encoding.UTF8, "application/json");
            HttpResponseMessage responseMsg       = new HttpResponseMessage()
            {
                Content = responseMsgString
            };

            responseResult = ResponseMessage(responseMsg);

            return(responseResult);
        }
Esempio n. 3
0
        /// <summary>
        /// 取得所有公車路線(含關鍵字)
        /// </summary>
        /// <param name="cityType">Taipei: 1, NewTaipei: 2, Taoyuan: 3, Taichung: 4, Tainan: 5,
        ///Kaohsiung: 6, Keelung: 7, Hsinchu: 8, HsinchuCounty: 9, MiaoliCounty: 10,
        ///ChanghuaCounty: 11, NantouCounty: 12, YunlinCounty: 13, ChiayiCounty: 14, Chiayi: 15,
        ///PingtungCounty: 16, YilanCounty: 17, HualienCounty: 18, TaitungCounty: 19, KinmenCounty: 20,
        ///PenghuCounty: 21, PenghuCounty: 22</param>
        ///<param name="keyWord">關鍵字搜尋</param>
        /// <returns></returns>
        public List <GetRoute> GetRoute(int cityType, string keyWord)
        {
            IBusRoute repos = DataFactory.BusRouteRepository();

            return(repos.GetRoute(cityType, keyWord));
        }