public async Task <int> GetUserCountFb(string email) { ConnectToFirebase(); //string userName = DAO.GetUserID(); String myUsername = email; myUsername = myUsername.Replace(".", "-"); String node = "CounterRecord" + "/"; int cntNum = 0; FbCnt fbCnt = new FbCnt { username = myUsername, }; var results = await firebase.Child(node).OnceAsync <FbCnt>(); foreach (var details in results) { if (details.Object.username == myUsername) { cntNum = details.Object.cnt; break; } } return(cntNum); }
/// <summary> /// Create a counter record in Firebase. Is created once per user when they create an accoount. /// </summary> /// <param name="counterNum"></param> public async void CreateCountRecordFB1(int counterNum) { ConnectToFirebase(); string userName = DAO.GetUserID(); String myUsername = userName; myUsername = myUsername.Replace(".", "-"); String node = "CounterRecord" + "/"; FbCnt fbCnt = new FbCnt { cnt = counterNum, username = myUsername, }; await firebase.Child(node).PostAsync <FbCnt>(fbCnt); }
/// <summary> /// Update Firebase count /// </summary> /// <param name="counterNum"></param> public async void UpdateCountRecordFB(int counterNum) { ConnectToFirebase(); try { string userName = DAO.GetUserID(); String myUsername = userName; myUsername = myUsername.Replace(".", "-"); String node = "CounterRecord" + "/"; FbCnt fbCnt = new FbCnt { cnt = counterNum, username = myUsername, }; var results = await firebase.Child(node).OnceAsync <FbCnt>(); foreach (var details in results) { if (details.Object.username == myUsername) { //Delete the old row by key Id await firebase.Child(node).Child(details.Key).DeleteAsync(); } } //Add a new row. await firebase.Child(node).PostAsync <FbCnt>(fbCnt); } catch { Debug.WriteLine("No Internet Connection"); } }