using Justice.Models; using Justice.Views; using Justice.Helpers; namespace Justice.Views; public partial class AddContactPage : ContentPage { private readonly DatabaseHelper _databaseHelper; public AddContactPage() { InitializeComponent(); _databaseHelper = new DatabaseHelper(); } private async void OnSaveContactClicked(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(NameEntry.Text) || string.IsNullOrWhiteSpace(MobileNumberEntry.Text) || GroupPicker.SelectedItem == null) { await DisplayAlert("Error", "All Fields Required", "OK"); } var contact = new EmergencyContact { Name = NameEntry.Text, MobileNumber = MobileNumberEntry.Text, Group = GroupPicker.SelectedItem.ToString() }; await _databaseHelper.InsertAsync(contact); await DisplayAlert("Success", "Contact Saved Successfully", "OK"); await Navigation.PushAsync(new EmergencyContactsPage()); } catch (Exception ex) { await DisplayAlert("Success", $"{ex}", "OK"); } } }