コード例 #1
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");
        }
コード例 #2
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);
        }
コード例 #3
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);
        }