コード例 #1
0
        /// <summary>
        /// Gets a list of geoname-objects by searching on its name 
        /// in either the database or the webservice
        /// </summary>
        /// <param name="locationName">Input search string</param>
        /// <returns>List of geoName Objects</returns>
        public List<GeoName> FindLocations(string locationName)
        {
            var locations = this._repository.QueryGeoNames().Where(g => g.name.Contains(locationName)).ToList();

            if (locations.Count() == 0)
            {
                var webService = new GeoNamesWebService();
                locations = webService.FindGeoNames(locationName);

                foreach (var location in locations)
                {
                    this._repository.Add(location);
                }
                // ...save the user in the database.
                this._repository.Save();
                return locations;
            }
            return locations;
        }
コード例 #2
0
        /// <summary>
        /// Gets the geoName object via the users location
        /// For use with HTML5 Geolocation
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <returns></returns>
        public GeoName GetGeoNameByGeoLocation(string lat, string lng)
        {
            GeoNamesWebService geoNameWebservice = new GeoNamesWebService();
            GeoName geoName = geoNameWebservice.FindGeoLocation(lat, lng);

            if (this._repository.QueryGeoNames().Where(q => q.geoNameId == geoName.geoNameId).Count() == 0)
            {
                this._repository.Add(geoName);
                this._repository.Save();
            }
            return geoName;
        }