Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //if (txtCustomerFirstName.TextLength > 1)
            //{
            //    firstname = txtCustomerFirstName.Text.ToString();
            //}
            //if (txtCustomerLastName.TextLength > 1)
            //{
            //    lastname = txtCustomerLastName.Text.ToString();
            //}
            //for (int i = 0; i < emailCharacters.Length; i++)
            //{
            //    //set values of textbox3 to email and then check if it contains email characters?
            //    //if (textBox3.Contains(emailCharacters[i]))
            //    //{
            //        email = customerEmailAddress.Text.ToString();
            //    //}
            //}
            //validatePrimaryContactDetails(customerPrimaryContactText.Text.ToString());
            //validateSecondaryContactDetails(CustomerSecondaryContactText.Text.ToString());

            ////variables to be added to database
            //label6.Text = (firstname + " " + lastname + " " + email + " " + correctPrimaryContact + " " + correctSecondaryContact);

            ////sending data (after validation checks) to the database
            //using (var db = new DatabaseContext())
            //{
            //    if (!checkIfDoubleEntryEmail(email))
            //    {
            //        if (!checkIfDoubleEntryPrimaryPhone(primaryContact))
            //        {
            //            if (!checkIfDoubleEntryPrimaryPhone(secondaryContact))
            //            {
            //                Customer c = new Customer();
            //                c.player = new Player();
            //                c.player.Firstname = firstname;
            //                c.player.Lastname = lastname;
            //                c.EmailAddress = email;
            //                c.primaryContact = correctPrimaryContact;
            //                c.secondaryContact = correctSecondaryContact;

            //                db.Customers.Add(c);
            //                db.SaveChanges();
            //            }
            //        }
            //    }
            //    else
            //    {
            //        MessageBox.Show("Email Address, primary contact or secondary contact already found in database!");
            //    }
            //}
            if (txtCustomerFirstName.TextLength > 1)
            {
                customerFirstname = txtCustomerFirstName.Text;
            }
            if (txtCustomerLastName.TextLength > 1)
            {
                customerLastname = txtCustomerLastName.Text;
            }
            for (int i = 0; i < customerEmailCharacters.Length; i++)
            {
                customerEmail = customerEmailAddress.Text;
            }


            ValidationCustomer vc = new ValidationCustomer()
            {
                MobileNumber   = customerPrimaryContactText.Text,
                LandlineNumber = CustomerSecondaryContactText.Text,
                EmailAddress   = customerEmailAddress.Text,
                Firstname      = txtCustomerFirstName.Text,
                Lastname       = txtCustomerLastName.Text
            };


            vc = Validation.validateCustomerDetails(vc);
            //sending data (after validation checks) to the database
            using (var db = new DatabaseContext())
            {
                if (!Validation.checkIfDoubleEntryEmail(vc.EmailAddress))
                {
                    if (!Validation.checkIfDoubleEntryPrimaryPhone(vc.MobileNumber))
                    {
                        if (!Validation.checkIfDoubleEntryPrimaryPhone(vc.LandlineNumber))
                        {
                            Customer c = new Customer();
                            c.player           = new Player();
                            c.player.Firstname = vc.Firstname;
                            c.player.Lastname  = vc.Lastname;
                            c.EmailAddress     = vc.EmailAddress;
                            c.MobileNumber     = vc.MobileNumber;
                            c.LandlineNumber   = vc.LandlineNumber;

                            db.Customers.Add(c);
                            db.SaveChanges();
                            MessageBox.Show("Customer successfully added");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Email Address, primary contact or secondary contact already found in database!");
                }
            }
        }