Ejemplo n.º 1
0
        public IEnumerable<FamilyUser> GetFamilyOfUser(User user)
        {
            Request.CityApiRequest req = new Request.CityApiRequest();
            var familyResults = req.ExecuteGetRequestAndParse(_parentSession, string.Format("/users/{0}/family", user.ID));

            List<FamilyUser> familyUsers = new List<FamilyUser>();

            dynamic famMembers = familyResults["family_members"];

            foreach (var famMember in famMembers)
            {
                string famRole = famMember.family_role;
                double userId = famMember.user_id;

                familyUsers.Add(new FamilyUser() { FamilyRole = famRole, User = GetUserByID(Convert.ToInt32(userId)) });
            }

            return familyUsers;
        }
Ejemplo n.º 2
0
        public User GetUserByID(int userId)
        {
            if (_cache.IsCached<User>())
            {
                var cachedUsers = _cache.GetCachedItems<User>();
                var targetUser = cachedUsers.FirstOrDefault(g => g.ID == userId);

                if (targetUser != null) { return targetUser; }
            }

            if (_individualUserCache.ContainsKey(userId))
            {
                return _individualUserCache[userId];
            }

            Request.CityApiRequest req = new Request.CityApiRequest();
            var response = req.ExecuteGetRequestAndParse(_parentSession, string.Format("/users/{0}?include_custom_fields=true", userId));

            var u = new User(response);

            _individualUserCache[u.ID] = u;

            return u;
        }
Ejemplo n.º 3
0
 public IEnumerable<FamilyUser> GetParentsInFamilyOfUser(User user)
 {
     var familyUsers = GetFamilyOfUser(user);
     return familyUsers.Where(f => f.FamilyRole.ToUpperInvariant().Contains("CHILD") == false).ToList();
 }
Ejemplo n.º 4
0
 public IEnumerable<FamilyUser> GetChildrenInFamilyOfUser(User user)
 {
     var familyUsers = GetFamilyOfUser(user);
     return familyUsers.Where(f => f.FamilyRole.ToUpperInvariant() == "CHILD").ToList();
 }