상속: FourSquareEntity
        /// <summary>
        /// Transforms User object to lighter FUser object
        /// </summary>
        /// <param name="user">user object to transform</param>
        /// <returns>transformed lighter FUser object</returns>
        public static FUser TransformToFUser(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            return new FUser
            {
                Id = user.id,
                Name = user.firstName != null && user.lastName != null ?
                        user.firstName + " " + user.lastName : string.Empty,
                Photo = user.photo != null ? user.photo.prefix + user.photo.suffix.Substring(1) : string.Empty,
                HomeCity = user.homeCity,
                FriendsCount = user.friends != null ? user.friends.count : 0
            };
        }
예제 #2
0
        public ActionResult PreencherUsuarios()
        {
            SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret);
            BancoContext db = new BancoContext();
            int lastid = 13027;
            Dictionary<string, string> parametros = new Dictionary<string, string>();

            List<Banco.Models.User> lisUser = db.Users.Where(w => w.Sexo == null && w.Id > lastid).ToList();

            foreach (Banco.Models.User usuario in lisUser)
            {
                try
                {
                    FourSquare.SharpSquare.Entities.User us = new FourSquare.SharpSquare.Entities.User();
                    lastid = usuario.Id;
                    us = sharpSquare.GetUser(usuario.SquareId);
                    usuario.Sexo = us.gender;
                    usuario.countAmigos = (int)us.friends.count;
                    usuario.countCheckin = (int)us.checkins.count;
                    usuario.countTip = (int)us.tips.count;
                    usuario.cidadeNatal = us.homeCity;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    if (e.Message == "O servidor remoto retornou um erro: (403) Proibido.")
                    {
                        break;
                    }
                }
            }
            return View();
        }