public async Task<RestaurantInfo> GetRestaurantDescription (RestaurantInfo restaurantInfo) { if (this._inMemoryCache.Contains(restaurantInfo.ToString())) { return await Task.FromResult<RestaurantInfo> ((RestaurantInfo)this._inMemoryCache[restaurantInfo.ToString()]); } else { var result = await this._dataAccess.GetRestaurantDescription (restaurantInfo); this._inMemoryCache[restaurantInfo.ToString()] = result; return result; } }
/// <summary> /// Return a list of restaurants "near by" in a city or geo location with the given /// size and skipping the given number of restaurants before returning any restaurants. /// Note: If lat/lon is given then city is ignored and vice versa. /// </summary> /// <param name="givenSize">The size of the restaurant list expected</param> /// <param name="skipping">The restaurants to skip before adding restaurant to list</param> /// <param name="lat">Near by latitude</param> /// <param name="lon">Near by longitude</param> /// <param name="orCity">Near by city</param> /// <returns>Restaurant list</returns> public async Task<List<RestaurantInfo>> GetRestaurantListNearBy( FilterOptions filterOptions, double? lat = null, double? lon = null, string orCityId = null, int givenSize = 25, int skipping = 0) { System.Diagnostics.Debug.Assert((lat.HasValue && lon.HasValue) || !String.IsNullOrEmpty(orCityId)); var command = new LECommand("GetRestaurantListNearBy"); command.AddParam("format", "json"); if(String.IsNullOrEmpty(orCityId) == false) command.AddParam("cityid", orCityId); // this returns the command.AddParam("ginfo", "acdhprstm"); if (lat.HasValue) command.AddParam("lat", Convert.ToString(lat.Value)); if (lon.HasValue) command.AddParam("lon", Convert.ToString(lon.Value)); command.AddParam("top",Convert.ToString(givenSize)); command.AddParam("skip",Convert.ToString(skipping)); if (filterOptions != null) { foreach (var filterOption in filterOptions.AllOptions) { command.AddParam(filterOption.Name, filterOption.Value); } } JObject json = await this.DoGet(command); if(json == null) return new List<RestaurantInfo>(); var cnt = (int)json["Count"]; if (cnt > 0) { JArray restaurantArray = (JArray)json["Restaurants"]; return restaurantArray.Select<JToken, RestaurantInfo>(jObj => { RestaurantInfo restaurant = new RestaurantInfo(); restaurant.LocId = Convert.ToString((int)jObj["AddyID"]); restaurant.Id = Convert.ToString((int)jObj["RestID"]); restaurant.Name = (string)jObj["RestName"]; restaurant.StreetAddress = (string)jObj["Address1"]; if ((string)jObj["Address2"] != null) { restaurant.StreetAddress += (Environment.NewLine + (string)jObj["Address2"]); } restaurant.CityStateZip = String.Format("{0}, {1} {2}", (string)jObj["City"], (string)jObj["State"], (string)jObj["Zip"] ); restaurant.PhoneNumber = (string)jObj["Phone"]; restaurant.PriceRange = string.Empty; int avgCost = (int)jObj["AvgCost"]; for (int i = 0; i <= avgCost; i++) { restaurant.PriceRange += '$';//star - '\u2605'; } //CatInfoList var catList = (JArray)jObj["CatInfoList"]; restaurant.CategoryList = catList.Select<JToken, RestaurantInfo.CategoryInfo>(jCat => { return new RestaurantInfo.CategoryInfo() { Id = (string)jCat["CatID"], Name = (string)jCat["CatName"], IsBestOf = jCat["IsBestOf"] == null ? false : ((bool)jCat["IsBestOf"]) }; }); // Features/Amenities var featuresList = (JArray)jObj["AmendInfoList"]; restaurant.AmenityList = featuresList.Select<JToken, RestaurantInfo.AmenityInfo>(jAmen => { return new RestaurantInfo.AmenityInfo() { Id = (string)jAmen["AmendityID"], Name = (string)jAmen["AmendityName"], LocId = (string)jAmen["AddyID"] }; }); //MediaInfoList var mediaInfoList = (JArray)jObj["MediaInfoList"]; var mediaInfo = mediaInfoList.FirstOrDefault<JToken>(); if (mediaInfo != null) { //http://cdn.localeats.com/media/images/23132-1.jpg?dummy=dummy40 restaurant.ImageUri = String.Format(@"http://cdn.localeats.com/media/images/{0}?dummy=dummy40", (string)mediaInfo["MediaFileName"]); } if (jObj["DistanceAway"] != null) restaurant.SpatialOffset = (decimal)jObj["DistanceAway"]; // Awards if (jObj["AwardInfoList"] != null) { var jAwardList = (JArray)jObj["AwardInfoList"]; var awardList = new List<RestaurantInfo.AwardInfo>(); foreach (var awardObj in jAwardList) { var awardName = (string)awardObj["AwardName"]; // as switch later .. maybe if (((int)awardObj["AwardID"]) == ((int)Award.EditorsPick)) { restaurant.IsEditorsPick = true; // LE now refers to Top 100 as editors pick awardName = "Editors Pick"; } awardList.Add(new RestaurantInfo.AwardInfo() { Id = (string)awardObj["AwardID"], Name = awardName }); } restaurant.AwardList = awardList; } // Neighborhoods if (jObj["HoodInfoList"] != null) { var jHoodList = (JArray)jObj["HoodInfoList"]; restaurant.NeighborhoodList = jHoodList.Select<JToken, RestaurantInfo.NeighborhoodInfo>(jHood => { return new RestaurantInfo.NeighborhoodInfo() { Id = (string)jHood["HoodID"], Name = (string)jHood["HoodName"] }; }); } // Deals if (jObj["DealInfoList"] != null) { var jDealList = (JArray)jObj["DealInfoList"]; restaurant.DealList = jDealList.Select<JToken, RestaurantInfo.DealInfo>(jDeal => { return new RestaurantInfo.DealInfo() { Id = (string)jDeal["Id"], Description = (string)jDeal["Description"], StartDate = (DateTime)jDeal["StartDate"], Title = (string)jDeal["Title"] }; }); } return restaurant; }).ToList<RestaurantInfo>(); } else { return new List<RestaurantInfo>(); } }
/// <summary> /// Given the restaurant info get the description for the restaurant and return the same RestaurantInfo /// object updated with the description. /// </summary> /// <param name="restaurantInfo">The restaurant to get description for</param> /// <returns>The updated restaurant info</returns> public async Task<RestaurantInfo> GetRestaurantDescription(RestaurantInfo restaurantInfo) { var command = new LECommand("GetRestauranDescByAddyID"); command.AddParam("format", "json"); command.AddParam("addyid", restaurantInfo.LocId); JObject json = await this.DoGet(command); JObject restaurantObj = (JObject)json["Restaurant"]; restaurantInfo.Description = String.Format("{0} {1}", (string)restaurantObj["RestDesc"], (string)restaurantObj["RestCite"]); restaurantInfo.Serves = (string)restaurantObj["RestAddInfo"]; restaurantInfo.IsFullyLoaded = true; return restaurantInfo; }
/// <summary> /// Given the restaurant load it's description and return the updated version with the description loaded. /// </summary> /// <param name="restaurant">The restaurant to load the description for</param> /// <returns>The updated version of the given restaurant with the description loaded</returns> public async Task<RestaurantInfo> GetRestaurantDescription(RestaurantInfo restaurant) { return await this._leRepository.GetRestaurantDescription(restaurant); }