Example #1
0
        public async Task <IEnumerable <User> > GetUserFriends(string user_id)
        {
            FirebaseDB firebaseDB        = new FirebaseDB(BASE_URL);
            string     pathFavoriteBooks = user_id + "/friends";

            FirebaseDB       firebaseDBUserFavorites = firebaseDB.NodePath(pathFavoriteBooks);
            FirebaseResponse getResponse             = firebaseDBUserFavorites.Get();

            if (getResponse.JSONContent.Equals("null"))
            {
                return(new List <User>());
            }

            IEnumerable <string> friendMails = DeserializeFriends(getResponse.JSONContent).Keys;

            List <User> friends = new List <User>();

            foreach (string email in friendMails)
            {
                User u = GetUserByEmail(email);
                if (u != null)
                {
                    friends.Add(u);
                }
            }

            return(friends);
        }
Example #2
0
        public async Task <bool> CheckIfIsFavourite(string user_id, IElement element)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

            string path = user_id + GetRootOfElement(element.TypeElement);

            FirebaseDB firebaseDBUserFavorites = firebaseDB.NodePath(path);

            FirebaseResponse getResponse = firebaseDBUserFavorites.Get();

            if (getResponse.JSONContent.Equals("null"))
            {
                return(false);
            }

            IEnumerable <string> elementKeys = null;

            switch (element.TypeElement)
            {
            case (int)ElementType.Book: elementKeys = DeserializeBooks(getResponse.JSONContent).Keys;
                break;

            case (int)ElementType.Movie: elementKeys = DeserializeMovies(getResponse.JSONContent).Keys;
                break;

            case (int)ElementType.Song: elementKeys = DeserializeSongs(getResponse.JSONContent).Keys;
                break;
            }

            return(elementKeys == null ? false : elementKeys.Contains(element.Id));
        }
Example #3
0
        private User GetUserByEmail(string email)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

            FirebaseDB firebaseDBUsers = firebaseDB.NodePath("users/" + email);

            FirebaseResponse getResponse = firebaseDBUsers.Get();

            if (getResponse.Success)
            {
                string response = getResponse.JSONContent;

                if (response.Equals("null"))
                {
                    return(null);
                }
                else
                {
                    User u = JsonConvert.DeserializeObject <User>(response);

                    return(u);
                }
            }

            return(null);
        }
Example #4
0
        public IEnumerable <Song> GetFavouriteSongs(string user_id)
        {
            FirebaseDB firebaseDB        = new FirebaseDB(BASE_URL);
            string     pathFavoriteSongs = user_id + GetRootOfElement((int)ElementType.Song);

            FirebaseDB       firebaseDBUserFavorites = firebaseDB.NodePath(pathFavoriteSongs);
            FirebaseResponse getResponse             = firebaseDBUserFavorites.Get();

            if (getResponse.JSONContent.Equals("null"))
            {
                return(new List <Song>());
            }

            return(DeserializeSongs(getResponse.JSONContent).Values);
        }
Example #5
0
        public async Task <bool> CheckUserExists(User user)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

            FirebaseDB firebaseDBUsers = firebaseDB.NodePath("users/" + user.Email);

            FirebaseResponse getResponse = firebaseDBUsers.Get();

            if (getResponse.Success)
            {
                string response = getResponse.JSONContent;

                if (response.Equals("null"))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Example #6
0
        private bool CheckIfIsYourFriend(string user_id, string friend_email)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

            FirebaseDB firebaseDBUserFriend = firebaseDB.NodePath(user_id + "/friends/" + friend_email.Replace('.', ','));

            FirebaseResponse getResponse = firebaseDBUserFriend.Get();

            if (getResponse.Success)
            {
                string response = getResponse.JSONContent;

                if (response.Equals("null"))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }