public void AddUser(string username, string password, Action <StatusCode> completion) { if (!initialized) { completion(StatusCode.UNKNWON); return; } DocumentReference userRef = db.Collection("users").Document(username); StatusCode transactionStatus = StatusCode.OK; db.RunTransactionAsync(async transaction => { DocumentSnapshot user = await transaction.GetSnapshotAsync(userRef); if (user.Exists) { transactionStatus = StatusCode.USER_ALREADY_EXISTS; return(false); } transaction.Set(userRef, new Dictionary <string, object> { { "passwordHash", CreateMD5Hash(password) } }); return(true); }).ContinueWithOnMainThread(task => { completion(transactionStatus); }); }