Exemple #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);
        }
Exemple #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));
        }
Exemple #3
0
        public async Task <bool> AddFavourite(string user_id, IElement element)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

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

            FirebaseDB firebaseDBUserFavItems = firebaseDB.NodePath(path);

            if (element is Song)
            {
                ((Song)element).image  = null;
                ((Song)element).artist = null;
            }

            IDictionary <string, IElement> IdElementPair = new Dictionary <string, IElement>();

            IdElementPair.Add(element.Id, element);

            string favToAdd = JsonConvert.SerializeObject(IdElementPair);

            FirebaseResponse patchResponse = firebaseDBUserFavItems
                                             .Patch(favToAdd);

            return(patchResponse.Success);
        }
Exemple #4
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);
        }
Exemple #5
0
        public async Task <bool> RemoveFavourite(string user_id, IElement element)
        {
            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

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

            FirebaseDB firebaseDBRemoveFavMovies = firebaseDB.NodePath(path);

            FirebaseResponse deleteResponse = firebaseDBRemoveFavMovies
                                              .Delete();

            return(deleteResponse.Success);
        }
Exemple #6
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);
        }
Exemple #7
0
        public async Task <string> AddFriend(string user_id, string friend_email)
        {
            if (friend_email.Equals(AccountManager.GetAccountMail().Replace('.', ',')))
            {
                return("You cannot add yourshelve as a friend");
            }

            User u = GetUserByEmail(friend_email);

            if (u == null)
            {
                return("The user doesn't exist");
            }

            if (CheckIfIsYourFriend(user_id, friend_email))
            {
                return("The user is already your friend");
            }

            Friend friend = new Friend()
            {
                FriendId = u.Id
            };

            IDictionary <string, Friend> IdElementPair = new Dictionary <string, Friend>();

            IdElementPair.Add(friend_email, friend);

            FirebaseDB firebaseDB = new FirebaseDB(BASE_URL);

            string path = user_id + "/friends";

            FirebaseDB firebaseDBUserFavItems = firebaseDB.NodePath(path);

            string friendToAdd = JsonConvert.SerializeObject(IdElementPair);

            FirebaseResponse patchResponse = firebaseDBUserFavItems
                                             .Patch(friendToAdd);

            return(patchResponse.Success ? "Friend added correctly" : "A problem appears adding a friend");
        }
Exemple #8
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);
        }
Exemple #9
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);
        }