public void SetCRMAccount(CRMAccount crmAccount)
        {
            if (crmAccount != null)
            {
                m_crmAccount = crmAccount;
                SetStatusMessage(UPDATE_TEXT, false);

                m_crmType.SelectedIndex = m_crmType.Items.IndexOf(m_crmType.Items.Single(x => ((TextBlock)x).Text == crmAccount.CRMAccountType.ToString()));
                m_crmURL.Text = crmAccount.URL;
                m_crmUsername.Text = crmAccount.Username;
                m_crmPassword.Text = crmAccount.Password;

                m_deleteButton.IsEnabled = true;
            }
            else
            {
                m_crmAccount = null;
                SetStatusMessage(ADD_TEXT, false);

                m_crmURL.Text = String.Empty;
                m_crmUsername.Text = String.Empty;
                m_crmPassword.Text = String.Empty;

                m_deleteButton.IsEnabled = false;
            }
        }
        private string Validate(CRMAccount crmAccount)
        {
            var validationResults = new List<ValidationResult>();
            var validationContext = new ValidationContext(crmAccount, null, null);
            Validator.TryValidateObject(crmAccount, validationContext, validationResults);
            crmAccount.ValidationErrors.Clear();

            if (validationResults.Count > 0)
            {
                return validationResults[0].ErrorMessage;
            }
            else
            {
                // Do any other client side validation required.

                return null;
            }
        }
        private void Submit(object sender, System.Windows.RoutedEventArgs e)
        {
            if (m_crmAccount == null)
            {
                CRMAccount crmAccount = new CRMAccount()
                {
                    ID = Guid.Empty.ToString(),             // Will be set in the manager.
                    Owner = "None",                         // Will be set in the manager.
                    CRMTypeID = Enum.Parse(typeof(CRMAccountTypes), ((TextBlock)m_crmType.SelectedValue).Text, true).GetHashCode(),
                    URL = m_crmURL.Text,
                    Username = m_crmUsername.Text,
                    Password = m_crmPassword.Text,
                };

                string validationError = Validate(crmAccount);
                if (validationError != null)
                {
                    SetErrorMessage(validationError);
                }
                else
                {
                    Add(crmAccount);
                }
            }
            else
            {
                m_crmAccount.CRMTypeID = Enum.Parse(typeof(CRMAccountTypes), ((TextBlock)m_crmType.SelectedValue).Text, true).GetHashCode();
                m_crmAccount.URL = m_crmURL.Text;
                m_crmAccount.Username = m_crmUsername.Text;
                m_crmAccount.Password = m_crmPassword.Text;

                string validationError = Validate(m_crmAccount);
                if (validationError != null)
                {
                    SetErrorMessage(validationError);
                }
                else
                {
                    Update(m_crmAccount);
                }
            }
        }