private async void Search(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SearchTermText.Text)) { MessageBox.Show("Please enter a valid search term."); return; } List <User> results = await DirectorySearcher.SearchByAlias(SearchTermText.Text, new PlatformParameters(PromptBehavior.Auto, this.Handle)); if (results.Count == 0) { StatusResult.Text = "User Not Found. Try Another Term."; StatusResult.Foreground = new SolidColorBrush(Colors.Black); } else if (results[0].error != null) { StatusResult.Text = "Error! " + results[0].error; StatusResult.Foreground = new SolidColorBrush(Colors.Red); } else { StatusResult.Text = "Success"; StatusResult.Foreground = new SolidColorBrush(Colors.Green); } SearchResults.ItemsSource = results; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. SearchButton.TouchUpInside += async(object sender, EventArgs e) => { if (string.IsNullOrEmpty(SearchTermText.Text)) { StatusResult.Text = "Please Enter A Valid Search Term"; StatusResult.TextColor = UIColor.Black; GivenResult.Text = ""; SurnameResult.Text = ""; UpnResult.Text = ""; PhoneResult.Text = ""; return; } List <User> results = await DirectorySearcher.SearchByAlias(SearchTermText.Text, new PlatformParameters(this)); if (results.Count == 0) { StatusResult.Text = "User Not Found"; StatusResult.TextColor = UIColor.Black; GivenResult.Text = ""; SurnameResult.Text = ""; UpnResult.Text = ""; PhoneResult.Text = ""; } else if (results[0].error != null) { StatusResult.Text = "Error! " + results[0].error; StatusResult.TextColor = UIColor.Red; GivenResult.Text = ""; SurnameResult.Text = ""; UpnResult.Text = ""; PhoneResult.Text = ""; } else { StatusResult.TextColor = UIColor.Green; StatusResult.Text = "Success"; GivenResult.Text = results[0].givenName; SurnameResult.Text = results[0].surname; UpnResult.Text = results[0].userPrincipalName; PhoneResult.Text = results[0].telephoneNumber; } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.searchButton); button.Click += async delegate { EditText searchTermText = FindViewById <EditText>(Resource.Id.searchTermText); TextView statusResult = FindViewById <TextView>(Resource.Id.statusResult); TextView givenResult = FindViewById <TextView>(Resource.Id.givenResult); TextView surnameResult = FindViewById <TextView>(Resource.Id.surnameResult); TextView upnResult = FindViewById <TextView>(Resource.Id.upnResult); TextView phoneResult = FindViewById <TextView>(Resource.Id.phoneResult); if (string.IsNullOrEmpty(searchTermText.Text)) { statusResult.SetText(Resource.String.InvalidSearch); statusResult.SetTextColor(Color.White); givenResult.SetText(Resource.String.EmptyString); surnameResult.SetText(Resource.String.EmptyString); upnResult.SetText(Resource.String.EmptyString); phoneResult.SetText(Resource.String.EmptyString); return; } List <User> results = await DirectorySearcher.SearchByAlias(searchTermText.Text, new PlatformParameters(this)); if (results.Count == 0) { statusResult.SetText(Resource.String.UserNotFound); statusResult.SetTextColor(Color.White); givenResult.SetText(Resource.String.EmptyString); surnameResult.SetText(Resource.String.EmptyString); upnResult.SetText(Resource.String.EmptyString); phoneResult.SetText(Resource.String.EmptyString); } else if (results[0].error != null) { statusResult.SetText("Error! " + results[0].error, TextView.BufferType.Normal); statusResult.SetTextColor(Color.Red); givenResult.SetText(Resource.String.EmptyString); surnameResult.SetText(Resource.String.EmptyString); upnResult.SetText(Resource.String.EmptyString); phoneResult.SetText(Resource.String.EmptyString); } else { statusResult.SetText(Resource.String.Success); statusResult.SetTextColor(Color.Green); givenResult.SetText(results[0].givenName, TextView.BufferType.Normal); surnameResult.SetText(results[0].surname, TextView.BufferType.Normal); upnResult.SetText(results[0].userPrincipalName, TextView.BufferType.Normal); phoneResult.SetText(results[0].telephoneNumber, TextView.BufferType.Normal); } }; }