public static async void Search(CustomSearchControl SearchControl) { var client = Helper.getServiceClient(); AccountSubTypeQuery query = new AccountSubTypeQuery(); //by default we have an empty query if (SearchControl.OptionOne.IsChecked == true) { query = new AccountSubTypeQuery() { AccountType = int.Parse(SearchControl.SearchTextBox.Text) }; } else if (SearchControl.OptionTwo.IsChecked == true) { query = new AccountSubTypeQuery() { AccountSubType = int.Parse(SearchControl.SearchTextBox.Text) }; } //The search control needs to know the method it has to use inorder to search. So we pass a method SearchControl.Search = Search; int pagesize = SearchControl.PageSize; int pagePosition = SearchControl.PagePosition; var response = await client.QueryAccountSubTypeAsync(query, pagesize, pagePosition); //No response; exit if (response == null) { MessageBox.Show("Service isn't responding, please try again later", "Message", MessageBoxButton.OK, MessageBoxImage.Information); return; } SearchControl.ResultCount = response.TotalResultCount; //Fill the datagrid with the results SearchControl.ResultsGrid.ItemsSource = new ObservableCollection <FIN_AccountSubType>(response.Result.ToList <FIN_AccountSubType>());; }
//Normal Search method has been made resuable public static async void AccountSubTypeSearch(CustomSearchControl SearchControl) { var client = Helper.getServiceClient(); AccountSubTypeQuery query = new AccountSubTypeQuery(); if (SearchControl.OptionOne.IsChecked == true) { query = new AccountSubTypeQuery() { AccountType = int.Parse(SearchControl.SearchTextBox.Text) }; } if (SearchControl.OptionTwo.IsChecked == true) { query = new AccountSubTypeQuery() { AccountSubType = int.Parse(SearchControl.SearchTextBox.Text) }; } SearchControl.Search = AccountSubTypeSearch; int pagesize = SearchControl.PageSize; int pagePosition = SearchControl.PagePosition; var response = await client.QueryAccountSubTypeAsync(query, pagesize, pagePosition); if (response == null) { MessageBox.Show("Service isn't responding, please try again later", "Message", MessageBoxButton.OK, MessageBoxImage.Information); return; } SearchControl.ResultCount = response.TotalResultCount; var servicelist = response.Result.ToList <FIN_AccountSubType>(); var AccountSubTypes = new ObservableCollection <FIN_AccountSubType>(servicelist); SearchControl.ResultsGrid.ItemsSource = AccountSubTypes; }