private void addButton_Click(object sender, EventArgs e) { if (validateData(addressTb.Text)) { address a = new address(); a.country = country.countryId; a.address1 = addressTb.Text; if (crud.create(a) != null) { MessageBox.Show("Address was added!"); this.Close(); } else { MessageBox.Show("Address alredy exists!!!"); } } }
private bool checkNewAddress() { // creating of a new address // check possible address if (!r.IsMatch(cbAddress.Text)) { if (!cbAddress.Text.Contains(" ")) { MessageBox.Show("Incorect address!"); return(false); } } // check on a unique List <address> all = new List <address>(); all.AddRange(db.addresses); all = all.FindAll ( delegate(address a) { return(a.address1.Equals(cbAddress.Text)); } ); if (all.Count == 0) { // create a new address address a = new address(); a.address1 = cbAddress.Text; a.country = conferenceDTO.country; a = addressCrud.create(a); conferenceDTO.address = a.addressId; } return(true); }