public JsonResult GetExternalInfos(int id) { var backOffice = new Business.BackOffice(); Location location = backOffice.Locations.FirstOrDefault(l => l.Id == id); FoursquareVenue cacheItemFoursquare = null; if (!string.IsNullOrWhiteSpace(location.FoursquareID)) { string cacheKeyFoursquare = "foursquare-venue-" + location.FoursquareID; cacheItemFoursquare = (FoursquareVenue)WebCache.Get(cacheKeyFoursquare); if (cacheItemFoursquare == null) { cacheItemFoursquare = new FoursquareVenue(location.FoursquareID); WebCache.Set(cacheKeyFoursquare, cacheItemFoursquare, 1440); // one day cache } } GoogleNearby cacheItemGoogle = null; string cacheKeyGoogle = "google-nearby-" + location.Id; cacheItemGoogle = (GoogleNearby)WebCache.Get(cacheKeyGoogle); if (cacheItemGoogle == null) { cacheItemGoogle = new GoogleNearby(location.Latitude, location.Longitude); WebCache.Set(cacheKeyGoogle, cacheItemGoogle, 1440); // one day cache } return(Json(new LocationExternal(cacheItemFoursquare, cacheItemGoogle), JsonRequestBehavior.AllowGet)); }
public RestaurantResult(FoursquareVenue venue) { Id = venue.Id; Name = venue.Name; Address = venue.Location.Address; PostalCode = venue.Location.PostalCode; City = venue.Location.City; State = venue.Location.State; DeliveryUrl = venue.Delivery?.Url; }
private FoursquareVenue CreateVenueModel(FoursquareResponseVenue responseVenue, GeoCoordinate originCoordinate = null) { var facebookUser = responseVenue.Contact?.FacebookUsername ?? responseVenue.Contact?.Facebook; var facebookUrl = string.IsNullOrEmpty(facebookUser) ? null : $"https://www.facebook.com/{facebookUser}"; var mainCategory = responseVenue.Categories.FirstOrDefault(x => x.Primary) ?? responseVenue.Categories[0]; var coordinate = new GeoCoordinate(responseVenue.Location.Lat, responseVenue.Location.Lng); const int takeTopCategories = 2; var venue = new FoursquareVenue { Id = responseVenue.Id, Title = responseVenue.Name, Category = string.Join(", ", responseVenue.Categories .OrderBy(x => x.Primary ? 1 : 2) .Select(x => x.ShortName) .Take(takeTopCategories)), Coordinate = coordinate, Rating = responseVenue.Rating, RatingColor = responseVenue.RatingColor, MaxRating = VENUE_MAX_RATING, LikesCount = responseVenue.Likes?.Count, DistanceToPlacemark = _kmlCalculator.GetDistanceInMeters(originCoordinate, coordinate), Region = string.Join(", ", new[] { responseVenue.Location?.City, responseVenue.Location?.State, responseVenue.Location?.Country }.Where(x => x != null)), Address = responseVenue.Location?.Address == null ? null : string.Join(", ", responseVenue.Location?.FormattedAddress ?? new string[0]), ContactPhone = responseVenue.Contact?.FormattedPhone, Websites = new[] { responseVenue.ShortUrl, responseVenue.Url, facebookUrl }.Where(x => !string.IsNullOrEmpty(x)).ToArray(), IconUrl = new Uri($"{mainCategory.Icon.Prefix}{VENUE_ICON_SIZE}{mainCategory.Icon.Suffix}"), PriceLevel = responseVenue.Price?.Tier, PriceCurrency = responseVenue.Price?.Currency, PriceMaxLevel = VENUE_MAX_PRICE_LEVEL, Tags = responseVenue.Tags }; if ("public".Equals(responseVenue.BestPhoto?.Visibility, StringComparison.OrdinalIgnoreCase)) { venue.PhotoUrls = new[] { $"{responseVenue.BestPhoto?.Prefix}{VENUE_PHOTO_SIZE}{responseVenue.BestPhoto?.Suffix}" }; } if (responseVenue.Hours?.Timeframes != null) { var sb = new StringBuilder(); foreach (var timeframe in responseVenue.Hours.Timeframes) { if (sb.Length > 0) { sb.Append(", "); } sb.Append($"{timeframe.Days}: "); sb.Append(string.Join(", ", timeframe.Open.Select(o => o.RenderedTime))); } venue.OpeningHours = sb.ToString(); } if (responseVenue.Tips != null) { var tips = responseVenue.Tips.Groups[0].Items; venue.Tips = tips .Where(x => x.AgreeCount > 0) .Take(TOP_TIPS_TO_GET) .Select(tip => new FoursquareVenueTip { Message = tip.Text, Likes = tip.Likes.Count, AgreeCount = tip.AgreeCount, DisagreeCount = tip.DisagreeCount }).ToArray(); } if (venue.Websites.Length == 0) { venue.Websites = new[] { $"{VENUE_WEB_URL}{venue.Id}" }; } return(venue); }