Created
January 19, 2020 14:11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using XamarinFirebase.Helper; | |
using XamarinFirebase.Model; | |
namespace XamarinFirebase | |
{ | |
public partial class MainPage : ContentPage | |
{ | |
FirebaseHelper firebaseHelper = new FirebaseHelper(); | |
public MainPage() | |
{ | |
InitializeComponent(); | |
} | |
protected async override void OnAppearing() | |
{ | |
base.OnAppearing(); | |
var allPersons = await firebaseHelper.GetAllPersons(); | |
lstPersons.ItemsSource = allPersons; | |
} | |
private async void BtnAdd_Clicked(object sender, EventArgs e) | |
{ | |
await firebaseHelper.AddPerson(Convert.ToInt32(txtId.Text), txtName.Text); | |
txtId.Text = string.Empty; | |
txtName.Text = string.Empty; | |
await DisplayAlert("Success", "Person Added Successfully", "OK"); | |
var allPersons = await firebaseHelper.GetAllPersons(); | |
lstPersons.ItemsSource = allPersons; | |
} | |
private async void BtnRetrive_Clicked(object sender, EventArgs e) | |
{ | |
var person = await firebaseHelper.GetPerson(Convert.ToInt32(txtId.Text)); | |
if(person!=null) | |
{ | |
txtId.Text = person.PersonId.ToString(); | |
txtName.Text = person.Name; | |
await DisplayAlert("Success", "Person Retrive Successfully", "OK"); | |
} | |
else | |
{ | |
await DisplayAlert("Success", "No Person Available", "OK"); | |
} | |
} | |
private async void BtnUpdate_Clicked(object sender, EventArgs e) | |
{ | |
await firebaseHelper.UpdatePerson(Convert.ToInt32(txtId.Text), txtName.Text); | |
txtId.Text = string.Empty; | |
txtName.Text = string.Empty; | |
await DisplayAlert("Success", "Person Updated Successfully", "OK"); | |
var allPersons = await firebaseHelper.GetAllPersons(); | |
lstPersons.ItemsSource = allPersons; | |
} | |
private async void BtnDelete_Clicked(object sender, EventArgs e) | |
{ | |
await firebaseHelper.DeletePerson(Convert.ToInt32(txtId.Text)); | |
await DisplayAlert("Success", "Person Deleted Successfully", "OK"); | |
var allPersons = await firebaseHelper.GetAllPersons(); | |
lstPersons.ItemsSource = allPersons; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment