private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedCompanyCode.CompanyCodeID))
     {//check to see if key is part of the current list...
         CompanyCode query = CompanyCodeList.Where(item => item.CompanyCodeID == SelectedCompanyCode.CompanyCodeID &&
                                                   item.AutoID != SelectedCompanyCode.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back
             SelectedCompanyCode.CompanyCodeID = SelectedCompanyCodeMirror.CompanyCodeID;
             //change to the newly selected item...
             SelectedCompanyCode = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         CompanyCodeList = GetCompanyCodeByID(SelectedCompanyCode.CompanyCodeID);
         if (CompanyCodeList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedCompanyCode.CompanyCodeID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedCompanyCode = CompanyCodeList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedCompanyCode.CompanyCodeID != SelectedCompanyCodeMirror.CompanyCodeID)
         {
             SelectedCompanyCode.CompanyCodeID = SelectedCompanyCodeMirror.CompanyCodeID;
         }
     }
 }
 private void OnSearchResult(object sender, NotificationEventArgs <BindingList <CompanyCode> > e)
 {
     if (e.Data != null && e.Data.Count > 0)
     {
         CompanyCodeList     = e.Data;
         SelectedCompanyCode = CompanyCodeList.FirstOrDefault();
         Dirty       = false;
         AllowCommit = false;
     }
     UnregisterToReceiveMessages <BindingList <CompanyCode> >(MessageTokens.CompanyCodeSearchToken.ToString(), OnSearchResult);
 }