Esempio n. 1
0
        public async void OnAdd(object function)
        {
            ContactDatabase db = new ContactDatabase(dbPath);

            if (CheckFields())
            {
                switch (function)
                {
                case "Add":
                    var Contact = new Contact()
                    {
                        EmergencyName = emergencyName,
                        ContactName   = contactName,
                        ContactNumber = contactNumber
                    };
                    //   DependencyService.Get<IToast>().Toasts("custom",emergency);
                    DependencyService.Get <IToast>().Toasts("addContact", db.AddContact(Contact));
                    ContactName   = "";
                    ContactNumber = "";
                    MessagingCenter.Send <App>((App)Application.Current, "OnContactAdded");
                    break;

                case "Update":
                    var UpdateContact = await db.GetContactAsync(emergencyName, contactId);

                    UpdateContact.ContactName   = contactName;
                    UpdateContact.ContactNumber = contactNumber;
                    DependencyService.Get <IToast>().Toasts("updateContact", db.UpdateContact(UpdateContact));
                    MessagingCenter.Send <App>((App)Application.Current, "OnContactUpdated");
                    await PopupNavigation.Instance.PopAsync(true);

                    break;
                }
            }
            else
            {
                DependencyService.Get <IToast>().Toasts("addContact", "failed");
            }
        }