private void DeleteContractor()
 {
     try
     {
         if (MessageBox.Show("Are you sure you want to PERMANENTLY delete the Contractor's details?", "Delete Contractor?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
         {
             SelectedContractor.Delete();
             ContractorCollection.Remove(SelectedContractor);
             MessageBox.Show("Thank you!  The Contractor's details have been deleted!", "Delete Contractor?", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("An Error Occured, The Contractor Details have not been deleted. Please Contact your System Administrator.", "Delete Contractor?" + ex.Message);
     }
 }
        async void ContractorSelect()
        {
            if (ContractorList.Count > 0)
            {
                var contractor = await _dataService.GetContractor(SelectedContractor.Split(',')[0]);

                PermitInfo.ContractorID = SelectedContractor.Split(',')[1].ToString();
                PermitApplicant applicant = new PermitApplicant();
                applicant.ApplicantType = "Contractor";
                CCBNumber             = contractor.license_number;
                applicant.Name        = (!string.IsNullOrEmpty(contractor.alias_name) ? contractor.alias_name : contractor.business_name);
                applicant.Contact     = contractor.rmi_name;
                applicant.Address     = contractor.address;
                applicant.City        = contractor.city;
                applicant.State       = contractor.state;
                applicant.Zip         = contractor.zip;
                applicant.PhoneNumber = contractor.business_telephone;
                ApplicantInfo         = applicant;
                ContractorList.Clear();
                SearchKeyword = string.Empty;
            }
        }
        private void SaveContractor()

        {
            if (String.IsNullOrEmpty(SelectedContractor.FirstName))
            {
                MessageBox.Show("Please Enter First Name", "First Name Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (String.IsNullOrEmpty(SelectedContractor.LastName)

                )
            {
                MessageBox.Show("Please Enter Last Name", "Last Name Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (String.IsNullOrEmpty(SelectedContractor.MobileNumber))
            {
                MessageBox.Show("Please Enter Mobile Number", "Mobile Number Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (String.IsNullOrEmpty(SelectedContractor.State))
            {
                MessageBox.Show("Please Enter State", "State Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (String.IsNullOrEmpty(SelectedContractor.Suburb))
            {
                MessageBox.Show("Please Enter Suburb", "Suburb Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (String.IsNullOrEmpty(SelectedContractor.PostCode))
            {
                MessageBox.Show("Please Enter Postcode", "Postcode Required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Regex.Match(SelectedContractor.LastName, "^[a-zA-Z\\s\\,]*$").Success || String.IsNullOrEmpty(SelectedContractor.LastName))
            {
                MessageBox.Show("Not a valid Last Name");

                return;
            }
            if (!Regex.Match(SelectedContractor.FirstName, "^[a-zA-Z\\s\\,]*$").Success || String.IsNullOrEmpty(SelectedContractor.LastName))
            {
                MessageBox.Show("Not a valid First Name");

                return;
            }
            if (!Regex.Match(SelectedContractor.MobileNumber, "^04[0-9]{8}$").Success)
            {
                MessageBox.Show("Enter valid phone number.", "Phone Number",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (!Regex.Match(SelectedContractor.State, "[a-zA-Z]{2,3}$").Success)
            {
                MessageBox.Show("State not in the correct format!");
                return;
            }
            if (!Regex.Match(SelectedContractor.Suburb, "^[a-zA-Z\\s\\,]*$").Success)
            {
                MessageBox.Show("Please enter valid Suburb Name");
                return;
            }
            if (!Regex.Match(SelectedContractor.PostCode, "^[2-7]{1}[0-9]{3}$").Success)
            {
                MessageBox.Show("Please enter valid Postcode");
                return;
            }
            //MessageBox.Show(SelectedContractor.FirstName + " " + SelectedContractor.LastName + " " + SelectedContractor.DOB + " " + SelectedContractor.Gender + " " + SelectedContractor.Street + " " + SelectedContractor.State + " " + SelectedContractor.PostCode + " " + SelectedContractor.Suburb + " " + SelectedContractor.MobileNumber + " " + SelectedContractor.Email + " ");
            if (SelectedContractor.ContractorID == 0)
            {
                try
                {
                    SelectedContractor.Insert();
                    MessageBox.Show("Thank you!  The new Contractor's details have been added to the Database.", "Add Contractor", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong" + ex.Message);
                }
            }
            else
            {
                try
                {
                    SelectedContractor.Update();
                    MessageBox.Show("The Contractor's details have been updated in the Database.", "Update Contractor?", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An Error Occured, The Contractor Details were not updated. Please Contact your System Administrator.", "Update Contractor?" + ex.Message);
                }
            }
            IsEnabledRoster = true;
            IsEnabledSkill  = true;
            IsEnabledSuburb = true;
            IsEnabledAdd    = true;
            IsEnabledSave   = true;
            IsEnabledDelete = true;
        }