public ManageCustomersForm()
 {
     InitializeComponent();
     _db = new AppContext();
     _customerRepository = new CustomerRepository(_db);
     _searchCustomer = new Repository.Models.Customer();
 }
        private void btnSaveCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                bool validateFrom = true;
                var message = "Operation failed to add customer.";
                int result = 0;

                if (string.IsNullOrEmpty(txtCustomerName.Text))
                {
                    validateFrom = false;
                    message = "Please enter customer name.";
                }

                if (validateFrom)
                {

                    var customer = new Repository.Models.Customer()
                    {
                        Name = txtCustomerName.Text,
                        Email = txtCustomerEmail.Text,
                        ContactNo = txtCustomerContact.Text,
                        CustomerId = _editCustomer != null ? _editCustomer.CustomerId : 0
                    };


                    if (_editCustomer != null && _editCustomer.CustomerId > 0)
                    {
                        result = _customerRepository.UpdateCustomer(customer);
                    }
                    else
                    {
                        result = _customerRepository.AddCustomer(customer);
                    }


                    if (result > 0)
                    {
                        message = "Customer saved successfully.";

                        clearFormValue();
                        initGridView();
                    }
                    else
                    {
                        message = "Operation failed to save new customer.";
                    }

                }

                MessageBox.Show(message);

            }
            catch (Exception)
            {
                throw;
            }
        }
 void clearFormValue()
 {
     txtCustomerContact.Text = null;
     txtCustomerEmail.Text = null;
     txtCustomerName.Text = null;
     _editCustomer = new Repository.Models.Customer();
     _searchCustomer = new Repository.Models.Customer();
     dgCustomerList.ClearSelection();
 }
 void setEditFormFields(int row)
 {
     try
     {
         if (_customersList != null && _customersList.Count > 0)
         {
             tabCustomer.SelectedTab = tabPageForm;
             _editCustomer = _customersList[row];
             txtCustomerContact.Text = _editCustomer.ContactNo;
             txtCustomerEmail.Text = _editCustomer.Email;
             txtCustomerName.Text = _editCustomer.Name;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 private void btnClearSearch_Click(object sender, EventArgs e)
 {
     txtSearchContact.Text = null;
     txtSearchEmail.Text = null;
     txtSearchName.Text = null;
     _searchCustomer = new Repository.Models.Customer();
     initGridView();
 }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     try
     {
         _searchCustomer = new Repository.Models.Customer() { Name = txtSearchName.Text, Email = txtSearchEmail.Text, ContactNo = txtSearchContact.Text };
         initGridView();
     }
     catch (Exception)
     {
         throw;
     }
 }