Example #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!");
        }
Example #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!");
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            CustomerDTO dto = new CustomerDTO();

            dto.Name     = "Bilal";
            dto.Address  = "Lahore";
            dto.Accounts = new List <CustAccountsDTO>();

            dto.Accounts.Add(new CustAccountsDTO()
            {
                BankName      = "Alfalah",
                AccountNumber = "12345"
            });
            dto.Accounts.Add(new CustAccountsDTO()
            {
                BankName      = "Habib Bank",
                AccountNumber = "1234557"
            });

            CustomerDAL dal = new CustomerDAL();

            dal.SaveCustomer(dto);
        }