private async Task initialDataAsync() { List <User> listUser = await userFirebaseHelper.GetAllUser(); if (listUser.Count == 0) { await userFirebaseHelper.AddUser("Order", "1", "", "Order"); await userFirebaseHelper.AddUser("Manager", "1", "", "Manager"); await userFirebaseHelper.AddUser("Admin", "1", "", "Admin"); } }
async void OnSaveButtonClicked(object sender, EventArgs e) { bool valid = true; if (this.Entry_UserName.Text.Trim().Length == 0) { valid = false; await DisplayAlert("Error", "กรุณาระบุ User Name", "OK"); } if (valid && this.Entry_Password.Text.Trim().Length == 0) { valid = false; await DisplayAlert("Error", "กรุณาระบุ Password", "OK"); } if (valid && this.Entry_RePassword.Text.Trim().Length == 0) { valid = false; await DisplayAlert("Error", "กรุณาระบุ Re Password", "OK"); } if (valid && !this.Entry_RePassword.Text.Trim().Equals(this.Entry_Password.Text.Trim())) { valid = false; await DisplayAlert("Error", "กรุณาระบุ Password เท่ากับ Re Password", "OK"); } if (valid && this.picker.SelectedIndex == -1) { valid = false; await DisplayAlert("Error", "กรุณาระบุ User Level ", "OK"); } string userLevel = ""; int selectedIndex = picker.SelectedIndex; if (selectedIndex != -1) { userLevel = (string)picker.ItemsSource[selectedIndex]; } if (valid) { if (bt_Confirm.Text.Equals("Confirm Update")) { //Update await firebaseHelper.UpdateUser(this.user_id, this.Entry_UserName.Text.Trim(), this.Entry_Password.Text.Trim(), this.Entry_Detail.Text.Trim(), userLevel); await DisplayAlert("Complete", "Update Complete", "OK"); bt_Confirm.Text = "Confirm"; await Navigation.PushAsync(new ListUserAdmin()); } else { //Insert await firebaseHelper.AddUser(this.Entry_UserName.Text.Trim(), this.Entry_Password.Text.Trim(), this.Entry_Detail.Text.Trim(), userLevel); await DisplayAlert("Complete", "Insert Complete", "OK"); bt_Confirm.Text = "Confirm"; await Navigation.PushAsync(new ListUserAdmin()); } //end if } //end if }
//Inser a user public async Task <bool> AddUser(string email, string password) { return(await UserFirebaseHelper.AddUser(email, password)); }