private void AddCustomer_Click(object sender, EventArgs e) { try { string customerName = CustomerNameTextBox.Text; int addressId = AddressDao.GetAddressIdByString(Address1TextBox.Text); // create the address if one doesn't exist if (addressId == -1) { var newAddress = AddressDao.CreateAddress(Address1TextBox.Text, Address2TextBox.Text, Convert.ToInt32(CitySelectBox.SelectedValue), ZipTextBox.Text, PhoneTextBox.Text, DateTime.Now, DateTime.Now, LoginForm.username, LoginForm.username); bool added = AddressDao.SaveNewAddress(newAddress); if (added) { addressId = AddressDao.GetAddressIdByString(Address1TextBox.Text); } } if (customerName.Trim() != "" && addressId > 0) { var customer = CustomerDao.CreateCustomer(customerName, addressId, LoginForm.username); bool created = CustomerDao.SaveNewCustomer(customer); // clear out options CustomerNameTextBox.Text = null; Address1TextBox.Text = null; Address2TextBox.Text = null; PhoneTextBox.Text = null; ZipTextBox.Text = null; if (created == true) { SetDefaults(); MessageBox.Show($"Success! You have successfully added {customerName}."); } else { MessageBox.Show($"Something seems to have gone wrong, {customerName} was not created."); } } else { MessageBox.Show("Please make sure both a name and address are selected."); } } catch (Exception err) { MessageBox.Show("Couldn't create customer because: " + err); } }
public void CreateAddressTest() { var address = AddressDao.CreateAddress("123 Test Address", "456 Seccond Address", 1, "12345-9876", "123-456-7890", DateTime.Now, DateTime.Now, "system", "system"); Assert.IsInstanceOfType(address, typeof(Address)); }