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 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, 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_Clicked(object sender, EventArgs e) { var cnt = BindingContext as contact; if (cnt.FirstName == null) { await DisplayAlert("Alert", "Firstname should not be empty", "ok"); return; } else { if (!string.IsNullOrWhiteSpace(cnt.Id.ToString())) { //await DisplayAlert("Alert", cnt.FirstName, "ok"); cnt.Id = 1; ContactAdded?.Invoke(this, cnt); await Navigation.PopModalAsync(); } else { //await DisplayAlert("new", cnt.FirstName, "ok"); ContactUpdate?.Invoke(this, cnt); await Navigation.PopModalAsync(); } } }
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(); }
async void OnSave(object sender, System.EventArgs e) { await _connection.InsertOrReplaceAsync(NewContact); ContactAdded?.Invoke(this, NewContact); await Navigation.PopModalAsync(); }
// ======================================== // Callback to DHT to invoke event handlers public void ContactAddedToBucket(KBucket bucket, Contact contact) { ContactAdded?.Invoke(this, new ContactEventArgs() { Contact = contact }); }
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 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 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(); }
private async Task OnSave() { if (String.IsNullOrWhiteSpace(Contact.FullName)) { await _pageService.DisplayAlert("Error Add Contact", "Name cannot be empty", "OK"); return; } ContactAdded?.Invoke(this, Contact); }
private async void Button_Clicked(object sender, EventArgs e) { var contact = BindingContext as ContactEj; if (String.IsNullOrWhiteSpace(contact.FirstName)) { await DisplayAlert("Error", "Por favor ingrese el nombre.", "OK"); return; } if (contact.Id > 0) { ContactUpdate.Invoke(this, contact); } else { ContactAdded.Invoke(this, contact); } }
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(); }
/// <summary> /// Find a pending contact that goes into the bucket that now has room. /// </summary> protected void ReplaceWithPendingContact(KBucket bucket) { Contact contact; // Non-concurrent list needs locking while we query it. lock (pendingContacts) { contact = pendingContacts.Where(c => node.BucketList.GetKBucket(c.ID) == bucket).OrderBy(c => c.LastSeen).LastOrDefault(); if (contact != null) { pendingContacts.Remove(contact); bucket.AddContact(contact); PendingContactRemoved?.Invoke(this, new ContactEventArgs() { Contact = contact }); ContactAdded?.Invoke(this, new ContactEventArgs() { Contact = contact }); } } }
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(); }
public void AddToList(string str) { Book.Add(str); ContactAdded?.Invoke($"Contact {str} was added to the list"); }
protected virtual void OnContactAdded() { ContactAdded?.Invoke(this, EventArgs.Empty); }
private void OnContactAdded(ContactEventArgs e) { ContactAdded?.Invoke(this, e); }
private void OnContactAdded(Contact contact) { ContactAdded?.Invoke(this, new ContactEventArgs { ContactName = contact.Name }); }