You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
6 months ago
|
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");
|
||
|
}
|
||
|
}
|
||
|
}
|