Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            CustomerDTO dto = new CustomerDTO();
            //Get value from ID textbox
            int id = 0;

            Int32.TryParse(txtCustomerID.Text, out id);

            dto.CustomerID = id;
            dto.Name       = txtName.Text;
            dto.Address    = txtAddress.Text;

            CustomerDAL dal = new CustomerDAL();

            if (id == 0) //Insert Case
            {
                dal.SaveCustomer(dto);
            }
            else //update case
            {
                dal.UpdateCustomer2(dto);
            }

            MessageBox.Show("Record is saved!");
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            CustomerDTO dto = new CustomerDTO();
            //Get value from ID textbox
            int id = 0;

            Int32.TryParse(txtCustomerID.Text, out id);

            dto.CustomerID = id;
            dto.Name       = txtName.Text;
            dto.Address    = txtAddress.Text;

            var context = new ValidationContext(dto, serviceProvider: null, items: null);
            var results = new List <ValidationResult>();
            var isValid = Validator.TryValidateObject(dto, context, results, true);

            if (!isValid)
            {
                foreach (var validationResult in results)
                {
                    Console.WriteLine(validationResult.ErrorMessage);
                }
            }


            CustomerDAL dal = new CustomerDAL();

            if (id == 0) //Insert Case
            {
                dal.SaveCustomer(dto);
            }
            else //update case
            {
                dal.UpdateCustomer2(dto);
            }

            MessageBox.Show("Record is saved!");
        }