private async void SaveContact(object obj) { //check for bad name inputs if ((SelectedContact.FirstName.All(char.IsWhiteSpace) || SelectedContact.FirstName.Any(char.IsDigit)) || (!string.IsNullOrEmpty(SelectedContact.LastName) && (SelectedContact.LastName.All(char.IsWhiteSpace) || SelectedContact.LastName.Any(char.IsDigit)))) { await metroWindow.ShowMessageAsync("Warning", "Please enter a valid name!"); } else { //check for correct phone number input if (SelectedContact.Phone.All(char.IsDigit) && SelectedContact.Phone.Length >= 3 && SelectedContact.Phone.Length <= 15) { //check for bad email address input if (!string.IsNullOrEmpty(SelectedContact.Email) && (SelectedContact.Email.All(char.IsWhiteSpace) || !SelectedContact.Email.Contains("@"))) { await metroWindow.ShowMessageAsync("Warning", "Please enter a valid Email Address!"); } else { //check if a user has been selected if (SelectedContact.Id != 0) { try { await repository.UpdateContact(SelectedContact); } catch (Exception ex) { if (ex.Message == "Precondition Failed") { await metroWindow.ShowMessageAsync("Warning", "This contact list has been updated elsewhere and is now out of date, " + "your list will now be updated"); } } } else { await repository.AddContact(SelectedContact); } LoadDb(); } } else { await metroWindow.ShowMessageAsync("Warning", "Please enter a valid phone number!"); } } }
public ActionResult <Contact> CreateContact(Contact contact) { _contactRepo.AddContact(contact); return(NoContent()); }