Example #1
0
		public async Task<StateInfo> GetCities (StateInfo stateInfo)
		{
			if (this._inMemoryCache.Contains(stateInfo.ToString())) {
				return await Task.FromResult<StateInfo> ((StateInfo)this._inMemoryCache[stateInfo.ToString()]);
			} else {
				var result = await this._dataAccess.GetCities (stateInfo);

				this._inMemoryCache[stateInfo.ToString()] = result;

				return result;
			}
		}
Example #2
0
        /// <summary>
        /// Given the state info get the cities of that state and return
        /// the state populated with the cities on the gift card program.
        /// </summary>
        /// <param name="stateInfo">The state to get cities for</param>
        /// <returns>The given state with its cities loaded</returns>
        public async Task<StateInfo> GetCities(StateInfo stateInfo)
        {
            // GetCityListByStateID
            var command = new LECommand("GetCityListByStateID");

            //&top = -Indicates how many cities you want to pull back
            //-&format = -Tell it which format you would like the results in. Options are
            //xml and json
            //- &stateId = -Tell it which state to retrieve cities in by ID.
            command.AddParam("top","500");
            command.AddParam("format", "json");
            command.AddParam("stateId", Convert.ToString(stateInfo.Id));

            var json = await this.DoGet(command);

            var cnt = (int)json["Count"];

            if (cnt > 0)
            {
                var citiesArray = (JArray)json["Cities"];

                var cities = citiesArray.Select<JToken, CityInfo>(jt =>{
                    var city = new CityInfo();

                    city.Id = Convert.ToString((int)jt["D_City_ID"]);
                    city.Name = (string)jt["City_Name"];

                    return city;
                }).ToList<CityInfo>();

                stateInfo.Cities = cities;

                return stateInfo;
            }
            else
            {
                stateInfo.Cities = new List<CityInfo>();

                return stateInfo;
            }
        }
Example #3
0
        /// <summary>
        /// Return the list of states in the gift card program.
        /// </summary>
        /// <returns>List of states</returns>
        public async Task<List<StateInfo>> GetStates()
        {
            var command = new LECommand("GetAllMajorUSCites");

            //skip=0&top=500&format=json
            command.AddParam("format", "json");
            command.AddParam("top", "100");
            command.AddParam("skip", "0");

            var json = await this.DoGet(command);

            var cnt = (int)json["Count"];

            if (cnt > 0)
            {
                var majorCityArray = json["Cities"];

                return majorCityArray.Select<JToken, StateInfo>(jt =>
                {
                    var stateinfo = new StateInfo();

                    stateinfo.Id = (string)jt["State_ID"];

                    if (STATE_LONG_NAMES.ContainsKey((string)jt["StateShort"]) == false)
                        throw new DataException(String.Format("Unknown state short name. {0}", (string)jt["StateShort"]));

                    stateinfo.Name = STATE_LONG_NAMES[(string)jt["StateShort"]];

                    return stateinfo;
                })
                .OrderBy<StateInfo,string>(r => r.Name)
                .ToList<StateInfo>();
            }
            else
            {
                throw new DataException("No state information available.");
            }
        }
Example #4
0
        /// <summary>
        /// Return the list of cities that LocalEats supports in the given state.
        /// </summary>
        /// <param name="forState">The state to get cities for.</param>
        /// <returns>Cities list</returns>
        public async Task<IEnumerable<CityInfo>> GetCityList(StateInfo forState)
        {
            var state = await this._leRepository.GetCities(forState).ConfigureAwait(_configAwait);

            return state.Cities;
        }