async void OnSave(object sender, System.EventArgs e) { var contacts = BindingContext as Contacts; if (String.IsNullOrWhiteSpace(contacts.FullName)) { await DisplayAlert("Error", "Please enter the name.", "OK"); return; } if (contacts.Id == 0) { await _connection.InsertAsync(contacts); ContactAdded?.Invoke(this, contacts); } else { await _connection.UpdateAsync(contacts); ContactUpdated?.Invoke(this, contacts); } await Navigation.PopAsync(); }
private async void Button_Save_Clicked(object sender, EventArgs e) { var contact = BindingContext as Contact; if (String.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Error", "Full Name cannot be empty", "OK"); return; } if (contact.id == 0) { // This is just a temporary hack to differentiate between a // new and an existing Contact object. In the next section, // we'll store these Contact objects in a database. So, they // will automaticlaly get an Id. contact.id = 1; // This is null-conditional operator in C#. It is the same as: // // if (ContactAdded != null) // ContactAdded(this, contact); // // Read my blog post for more details: // http://programmingwithmosh.com/csharp/csharp-6-features-that-help-you-write-cleaner-code/ // ContactAdded?.Invoke(this, contact); } else { ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
async void btnSave_Clicked(object sender, EventArgs e) { var contact = BindingContext as ContactSQLite; if (string.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Warning", "Complete el nombre y apellido", "Aceptar"); return; } if (contact.Id == 0) { //contact.Id = 1; await _connection.InsertAsync(contact); ContactAdded?.Invoke(this, contact); } else { await _connection.UpdateAsync(contact); ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
private async Task SaveContact() { string errorMessage = string.Empty; if (!IsContactValid(out errorMessage)) { await _pageService.DisplayAlert("Error", errorMessage, "Ok"); return; } if (_isEditMode) { //Call Service or Persistence layer to add the contact model //Ex: await _contactService.AddContactAsync(Contact); //Ex: await _contactStore.AddContactAsync(Contact); ContactUpdated?.Invoke(this, Contact.Trim()); } else { //Call Service or Persistence layer to update the contact model //Ex: await _contactService.UpdateContactAsync(Contact); //Ex: await _contactStore.UpdateContactAsync(Contact); ContactAdded?.Invoke(this, Contact.Trim()); } await _pageService.PopAsync(); }
private async void OnSaved(object sender, EventArgs e) { var contact = BindingContext as Contact; if (String.IsNullOrWhiteSpace(contact.Name)) { await DisplayAlert("Error", "Please enter the name", "Ok"); return; } if (contact.Id == 0) { await _db.InsertAsync(contact); ContactAdded?.Invoke(this, contact); } else { await _db.UpdateAsync(contact); ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
async Task Save() { if (String.IsNullOrWhiteSpace(Contact.FirstName) && String.IsNullOrWhiteSpace(Contact.LastName)) { await _pageService.DisplayAlert("Error", "Please enter the name.", "OK"); return; } if (Contact.Id == 0) { await _contactStore.AddContact(Contact); ContactAdded?.Invoke(this, Contact); } else { await _contactStore.UpdateContact(Contact); ContactUpdated?.Invoke(this, Contact); } await _pageService.PopAsync(); }
private async void Save_OnTapped(object sender, EventArgs e) { var contact = BindingContext as Contact; if (String.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Error", "Please enter the name.", "OK"); return; } // Temporary hack to handle the difference between a create and an update if (contact.Id == 0) { // Create contact.Id = 1; ContactAdded?.Invoke(this, contact); } else { // Update ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
async void Save_Clicked(System.Object sender, System.EventArgs e) { var contact = BindingContext as Contact; if (string.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Error", "Please enter a name.", "Ok"); return; } if (contact.Id == 0) { await _connection.InsertAsync(contact); ContactAdded?.Invoke(this, contact); } else { await _connection.UpdateAsync(contact); ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
async void OnSave(object sender, EventArgs e) { var contact = BindingContext as Contact; //if the first name is empty, show an alert asking them to enter their first name. if (String.IsNullOrWhiteSpace(contact.FirstName)) { await DisplayAlert("Error", "Please enter your first name.", "Ok", "No thanks"); return; } //if it's a new contact, assign an id number to the new contact id if (contact.Id == 0) { await _connection.InsertAsync(contact); ContactAdded?.Invoke(this, contact); } else { await _connection.UpdateAsync(contact); ContactUpdated?.Invoke(this, contact); } //after all checked, pop this page off the stack. await Navigation.PopAsync(); }
async void OnSave(object sender, System.EventArgs e) { var contact = BindingContext as FormsContact; if (String.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Error", "Please enter the name.", "OK"); return; } if (contact.Id == 0) { // This is just a temporary hack to differentiate between a // new and an existing Contact object. In the next section, // we'll store these Contact objects in a database. So, they // will automaticlaly get an Id. contact.Id = 1; // This is null-conditional operator in C#. It is the same as: // // if (ContactAdded != null) // ContactAdded(this, contact); // // ContactAdded?.Invoke(this, contact); } else { ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
private async void Button_OnClicked(object sender, EventArgs e) { var contact = BindingContext as ContactBookRecord; if (string.IsNullOrWhiteSpace(contact.FullName)) { DisplayAlert("Error", "Please enter the name", "OK"); return; } if (contact.ID == 0) { contact.ID = 1; ContactAdded?.Invoke(this, contact); } else { ContactUpdated?.Invoke(this, contact); } await Navigation.PopAsync(); }
async void Button_Clicked(object sender, EventArgs e) { var contact = BindingContext as Models.Contacts; if (String.IsNullOrWhiteSpace(contact.FullName)) { await DisplayAlert("Error", "Please enter the name", "ok"); return; } if (contact.Id == 0) { contact.Id = 1; ContactAdded?.Invoke(this, contact); } else { ContactUpdated.Invoke(this, contact); } await Navigation.PopAsync(); }
protected virtual void OnContactUpdated(MUser e) => ContactUpdated?.Invoke(this, e);