Ejemplo n.º 1
0
        /// <summary>
        ///     Picks a random zip code and city for the given state
        /// </summary>
        /// <param name="random"> </param>
        /// <param name="state"> </param>
        /// <param name="zip"> </param>
        /// <param name="town"> </param>
        protected virtual void GenerateCity(Random random, string state, out string zip, out string town)
        {
            var zipMatches = PostalCodes.Where(z => z.State.Equals(state, StringComparison.OrdinalIgnoreCase)).ToList();

            var postalCode = zipMatches[random.Next(zipMatches.Count())];

            zip  = postalCode.Zip;
            town = postalCode.Town;
        }
        public async Task <GeoLocationCity> PostalCodeToLocationAsync(int postalCode)
        {
            var tcs    = new TaskCompletionSource <GeoLocationCity>();
            var result = await TaskEx.Run <GeoLocationCity>(() =>
            {
                var query = PostalCodes.Where(item => item.PostalCode == postalCode).FirstOrDefault();
                if (query == null)
                {
                    return(GeoLocationCity.UnkownCity());
                }
                return(query);
            });

            return(result);
        }