public LocationResponse Post(LocationRequest request) { DbContext context = new DbContext(); string bing = string.Format("http://dev.virtualearth.net/REST/v1/Locations/{0},{1}?o=json&key={2}", request.Point.Latitude, request.Point.Longitude, System.Web.Configuration.WebConfigurationManager.AppSettings["BingApiToken"].ToString()); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(bing); WebResponse webResponse = webRequest.GetResponse(); string statusDescription = ((HttpWebResponse)webResponse).StatusDescription; Stream stream = webResponse.GetResponseStream(); StreamReader reader = new StreamReader(stream); string json = reader.ReadToEnd(); reader.Close(); stream.Close(); webResponse.Close(); JObject jObject = JObject.Parse(json); string rawCountry = ((string)jObject.SelectToken("resourceSets[0].resources[0].address.countryRegion")).ToUpper().Replace(" ", string.Empty); Country country = (context.Countries.Where(c => c.CountryName.ToUpper() == rawCountry)).SingleOrDefault(); string rawProvince = ((string)jObject.SelectToken("resourceSets[0].resources[0].address.adminDistrict")).ToUpper().Replace(" ", string.Empty).Replace("CITY", string.Empty); Province province = (context.Provinces.Where(p => p.ProvinceName.ToUpper().Replace(" ", string.Empty) == rawProvince)).SingleOrDefault(); LocationResponse response = new LocationResponse(); response.Point = request.Point; response.CountryCode = country.CountryCode; response.CountryName = country.CountryName; response.ProvinceCode = province.ProvinceCode; response.ProvinceName = province.ProvinceName; return response; }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง