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