private async Task AddContact() { var viewModel = new ContactDetailPageViewModel(new Contact()); var page = new ContactDetailPage(viewModel); await Subscribe_ContactDetail_Add(page, viewModel); }
private async Task Subscribe_ContactDetail_Add(ContactDetailPage page, ContactDetailPageViewModel viewModel) { SelectedContact = null; viewModel.ContactAdded += async(source, args) => { bool isAdd = args.Id == 0; if (isAdd) { Contacts.Add(args); await _contactService.AddContact(args); } else { var existingContact = Contacts.Where(x => x.Id == args.Id).FirstOrDefault(); Contacts[Contacts.IndexOf(existingContact)] = args; await _contactService.UpdateContact(args); } await _pageService.DisplayAlert("Add Contact", string.Format("Contact has been {0}", (isAdd) ? "added" : "modified"), "OK"); await _pageService.PopAsync(); }; await _pageService.PushAsync(page); }
private async Task Contact_Selected(Contact contactSelected) { if (contactSelected == null) { return; } SelectedContact = contactSelected; var viewModel = new ContactDetailPageViewModel(contactSelected); var page = new ContactDetailPage(viewModel); await Subscribe_ContactDetail_Add(page, viewModel); }