예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string name  = txtName.Text;
            string email = txtEmail.Text;


            if (!string.IsNullOrWhiteSpace(name) || !string.IsNullOrWhiteSpace(email))
            {
                if (IsEmailValid(email))
                {
                    Customer client = new Customer(++this.customerId, name, email);

                    if (notExists(client))
                    {
                        customerData.Add(client);
                    }
                    else
                    {
                        customerData.UpdateById(client, customerData.GetCustomers());
                    }

                    UpdateCustomerList();
                }
                else
                {
                    MessageBox.Show("Invalid email!");
                }
            }
            clearFields();
        }
예제 #2
0
        public static Customer AddCustomer(this CustomerData customerData, string firstName, string lastName, string address, string city, string state, string zipCode)
        {
            int      customerNumber = customerData.Any() ? customerData.Max(m => m.CustomerNumber) + 1 : CustomerData.CustomerNumberSeed;
            Customer customer       = new Customer()
            {
                CustomerNumber = customerNumber, FirstName = firstName, LastName = lastName, Address = address, City = city, State = state, ZipCode = zipCode
            };

            customerData.Add(customer);
            return(customer);
        }