public FunPlaceDetail(FunPlace place) { FoursquareId = place.FoursquareId; Name = place.Name; Latitude = place.Latitude; Longitude = place.Longitude; FriendCount = place.FriendCount; Comments = new List<Comment>(); Categories = new List<string>(); StartTime = place.StartTime; Artists = place.Artists; }
public static RouteValueDictionary GetRVD(FunPlace place) { var rvd = new RouteValueDictionary(); //fill it //rvd["Name"] = place.Name; rvd["Latitude"] = place.Latitude; rvd["Longitude"] = place.Longitude; rvd["FriendCount"] = place.FriendCount; rvd["FoursquareId"] = place.FoursquareId; //rvd["StartTime"] = place.StartTime; //rvd["Artists"] = place.Artists; return rvd; }
public ActionResult FunResults() { var results = new List<FunPlace>(); var funSearch = GetFunSearch(Request.Params); var today = DateTime.Now; //case concert : if (funSearch.FunType == 3) { using (var client = new WebClient()) { client.Encoding = Encoding.UTF8; try { var location = funSearch.Latitude + "," + funSearch.Longitude; var path = string.Format(Songkick, location); string textString = client.DownloadString(path); JObject songKickJson = JObject.Parse(textString); var concerts = songKickJson["resultsPage"]["results"]["event"]; foreach (var c in concerts) { try { var dateStr = (string)c["start"]["date"]; var date = DateTime.Parse(dateStr); if (today.Date != date.Date) continue; var toAdd = new FunPlace() { Name = (string)c["displayName"], Latitude = (double)c["location"]["lat"], Longitude = (double)c["location"]["lng"], StartTime = (string)c["start"]["time"] }; var performances = c["performance"]; foreach (var p in performances) { toAdd.Artists += p["displayName"] + ","; } toAdd.Artists = toAdd.Artists.TrimEnd(','); Session["SKName"] = (string)c["displayName"]; Session["SKStartTime"] = (string)c["start"]["time"]; Session["SKArtists"] = toAdd.Artists; results.Add(toAdd); } catch (Exception) { continue; } } } catch (WebException) { } } //find nearest 4SQ foreach (var item in results) { using (var client = new WebClient()) { client.Encoding = Encoding.UTF8; try { var path = string.Format(FoursquareSearch, GetTokenKey()); var query = path + "&ll=" + item.Latitude + "," + item.Longitude + "&limit=20"; string textString = client.DownloadString(query); JObject venuesJson = JObject.Parse(textString); var venues = venuesJson["response"]["venues"]; var distList = new List<VenueSummary>(); foreach (var venue in venues) { var lat = (double)venue["location"]["lat"]; var lng = (double)venue["location"]["lng"]; var id = (string)venue["id"]; var toAdd = new VenueSummary { Lat = (double)venue["location"]["lat"], Lng = (double)venue["location"]["lng"], Id = (string)venue["id"], HereNow = (int)venue["hereNow"]["count"], Dist = GetDistance(item.Latitude, item.Longitude, lat, lng) }; distList.Add(toAdd); } var nearest = distList.Min(v => v.Dist); var nearestVenue = (from v in distList where v.Dist == nearest select v).FirstOrDefault(); item.FoursquareId = nearestVenue.Id; item.FriendCount = nearestVenue.HereNow; } catch (WebException) { item.FoursquareId = ""; } } } } else { using (var client = new WebClient()) { client.Encoding = Encoding.UTF8; try { var path = string.Format(FoursquareSearch, GetTokenKey()); var query = path + "&ll=" + funSearch.Latitude + "," + funSearch.Longitude;// +"&limit=20"; var toMatch = string.Empty; switch(funSearch.FunType) { case 0: toMatch = "Musée"; break; case 1: toMatch = "Restaurant"; break; case 2: toMatch = "Vie nocturne"; break; default: break; } //query += "&query=" + filter; string textString = client.DownloadString(query); JObject venuesJson = JObject.Parse(textString); var venues = venuesJson["response"]["venues"]; foreach (var v in venues) { try { var categories = v["categories"]; var found = false; foreach (var c in categories) { var cat = (string)c["name"]; if (cat.Contains(toMatch) || (string.Compare((string)c["name"], toMatch, true) == 0)) { found = true; break; } } if (found == false) continue; var toAdd = new FunPlace() { Name = (string)v["name"], Latitude = (double)v["location"]["lat"], Longitude = (double)v["location"]["lng"], FoursquareId = (string)v["id"], FriendCount = (int)v["hereNow"]["count"] }; results.Add(toAdd); } catch (Exception) { continue; } } } catch (WebException) { } } } return View(results); }
public ActionResult FunDetail(FunPlace place) { var detail = new FunPlaceDetail(place); detail.Name= (string)Session["SKName"]; detail.StartTime = (string)Session["SKStartTime"]; detail.Artists = (string)Session["SKArtists"]; //get 4SQ details using (var client = new WebClient()) { client.Encoding = Encoding.UTF8; try { var path = string.Format(FoursquareDetail, place.FoursquareId, GetTokenKey()); string textString = client.DownloadString(path); JObject foursquareJson = JObject.Parse(textString); var venue = foursquareJson["response"]["venue"]; var mayor = venue["mayor"]["user"]; if (mayor != null) { detail.Mayor = new Mayor { FirstName = (string)mayor["firstName"], LastName = (string)mayor["lastName"], Photo = (string)mayor["photo"], Gender = (string)mayor["gender"], }; } //comments var groups = venue["tips"]["groups"]; foreach (var g in groups) { var tips = g["items"]; foreach (var t in tips) { detail.Comments.Add(new Comment { Author = (string)t["user"]["firstName"], Post = (string)t["text"] }); } } //categories var categories = venue["categories"]; foreach (var c in categories) { detail.Categories.Add((string)c["shortName"]); } var photos = venue["photos"]["groups"]; foreach (var p in photos) { var items = p["items"]; foreach (var i in items) { var url = (string)i["url"]; if (!string.IsNullOrEmpty(url)) { detail.Image = url; break; } } } } catch (WebException) { } } return View(detail); }