private async Task DeleteContact(ContactViewModel contactViewModel) { if (await _pageService.DisplayAlert("Warning", $"Are you sure you want to delete {contactViewModel.FullName}?", "Yes", "No")) { Contacts.Remove(contactViewModel); var contact = await _contactStore.GetContact(contactViewModel.Id); await _contactStore.DeleteContact(contact); } }
private async Task DeleteContact(ContactViewModel contactViewModel) { var a = ""; if (await _pageService.DisplayAlert("Warning", $"Are you sure you want to delete {contactViewModel.FullName}?", "Yes", "No")) { Contacts.Remove(contactViewModel); // We're working with ContactViewModel objects on this page. // But to delete a contact, we need a Contact object. Here // we're getting the Contact again from the database. Another // solution would be to store the Contact objects we initially // fetch. But this would require additional memory and as the // number of contacts grows, it can take unnecessary amount of // memory on the device. So, I prefer to get the contact explicitly // here. var contact = await _contactStore.GetContact(contactViewModel.Id); await _contactStore.DeleteContact(contact); } }