コード例 #1
0
        public List <Profile> GetNearbyUsers(string userId, string token)
        {
            int uId = Convert.ToInt32(userId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                InitializeOauth(token);
                try
                {
                    //TODO add param
                    List <int>     nearbyUsersIds = foursquareOAuth.GetNearByUsers(1000);
                    List <Profile> nearbyUsers    = new List <Profile>();
                    foreach (var nearbyUsersId in nearbyUsersIds)
                    {
                        nearbyUsers.Add(foursquareOAuth.GetProfileInfo(nearbyUsersId));
                    }
                    return(nearbyUsers);
                }
                catch (Exception e)
                {
                    return(new List <Profile>());
                }
            }
            return(null);
        }
コード例 #2
0
        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] }));
        }
コード例 #3
0
        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());
        }