示例#1
0
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            // Quickest, most efficient way to do it; uses Linq
            // FirstOrDef takes IEnumerable and returns an instance of IEnumerable???
            // Tries to keep the IEnumerable alive as long as possible to chain it to other functions
            // Iterates through and checks which are of type RadioButton
            // Checks where the Checked property is true
            // FirstOrDefault - pins it to one value, a reducing function
            // Microsoft are v proud of Linq and have written it for almost any data set out there
            // They started a project Linq To SQL, so you could just know Linq not SQL
            var checkedButton = this.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

            if (txtForename.Text != "" && datDob.Text != "" && checkedButton.Text != "")
            {
                int newlyMadeID = CustomerDAL.AddNewCustomer(new Customer(txtForename.Text, datDob.Value, checkedButton.Text));

                if (newlyMadeID > -1)
                {
                    string newsflash = txtForename.Text + " has been successfully added, with Customer ID " + newlyMadeID;
                    MessageBox.Show(newsflash);
                    // lblIdMsg.Text = "Customer ID " + newlyMadeID;
                    tssText.Text = newsflash;
                    ClearForm();
                }
                else
                {
                    MessageBox.Show("ERROR: NO NEW CUSTOMER ADDED.  Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please complete all fields");
            }
        }
 public bool AddNewCustomer(CustomerModel customer)
 {
     if (customerDAL.IfEmployeeIdExists(customer.CustomerEmail))
     {
         return(false);
     }
     return(customerDAL.AddNewCustomer(customer));
 }
示例#3
0
 public string AddNewCustomer(string jsonCustomerDTO)
 {
     m_dataRequest  = JSonHelper.ConvertJSonToObject(jsonCustomerDTO);
     m_dataResponse = m_dalCustomer.AddNewCustomer(m_dataRequest.ResponseDataCustomerDTO);
     return(JSonHelper.ConvertObjectToJSon(m_dataResponse));
 }