public ActionResult RandomChat(int radius, string gender) { if (!User.Identity.IsAuthenticated) return RedirectToAction("Index", "FoursquareLogin"); String token = GetCurrentUserToken(); FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token); List<int> users = foursquareOAuth.GetNearByUsers(radius); if (Convert.ToBoolean(GetProfileInfo(Convert.ToInt32(User.Identity.Name))["isPremium"]) && gender != null) { for (int i = 0; i < users.Count; ++i) { NameValueCollection nv = GetProfileInfo(users[i]); if(gender != nv["gender"]) users.RemoveAt(i--); } } if(users.Count == 0) { ViewBag.error = "Sorry. Nobody to chat"; return View("CustomError"); } Random random = new Random(); int pos = random.Next(0, users.Count); return RedirectToAction("Chat", new {id = users[pos]}); }
public ActionResult NearbyUsers() { //TODO redirect to Friends if (!User.Identity.IsAuthenticated) return RedirectToAction("Index", "FoursquareLogin"); string token = GetCurrentUserToken(); Logic.FoursquareOAuth FSQOAuth = new FoursquareOAuth(token); Models.FoursquareUserContext db = new FoursquareUserContext(); IEnumerable<FoursquareUserModel> foursquareUsers = db.FoursquareUsers; foreach (var foursquareUserModel in foursquareUsers) { Logic.FoursquareOAuth tmp = new FoursquareOAuth(foursquareUserModel.Token); foursquareUserModel.LastVenueID = tmp.GetLastVenue(); UpdateModel(foursquareUserModel); logger.Debug("Got last venue " + foursquareUserModel.FoursquareUserId); } db.SaveChanges(); logger.Debug("Got all venues"); List<int> res = FSQOAuth.GetNearByUsers(1000); logger.Debug("got nearby users"); List<string> names = new List<string>(); for (int i = 0; i < res.Count; ++i) { NameValueCollection tmp; if (res[i] != null) { tmp = GetProfileInfo(res[i]); names.Add(tmp["firstname"]); } else { res.Remove(i); } } logger.Debug("got profile info"); ViewBag.users = res; ViewBag.names = names; return View(); }