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); }
public async Task <bool> AddUser(User user) { FirebaseDB firebaseDB = new FirebaseDB(BASE_URL); FirebaseDB firebaseDBUsers = firebaseDB.Node("users"); IDictionary <string, User> IdElementPair = new Dictionary <string, User>(); IdElementPair.Add(user.Email, user); string userToAdd = JsonConvert.SerializeObject(IdElementPair); FirebaseResponse patchResponse = firebaseDBUsers .Patch(userToAdd); return(patchResponse.Success); }
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"); }