Ejemplo n.º 1
0
 private async void AutoSearch_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
 {
     if (sender.Text.Length >= 1)
     {
         string text = NameMap.ChangeMap(sender.Text);
         await GetLabel(text);
         await GetArtical(text);
         await GetQusiton(text);
         await GetPeople(text);
     }
     else
     {
         sender.PlaceholderText = "输入内容";
     }
 }
        private async Task GetPeople(string text)
        {
            HttpClient httpClient = new HttpClient
            {
                BaseAddress = new System.Uri("http://localhost:60671/")
            };

            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            string sql = $"api/values/getbyname/{NameMap.ChangeMap(text)}";
            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(sql);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                peoples = await httpResponseMessage.Content.ReadAsAsync <List <People> >();

                if (peoples != null)
                {
                    Peoplelist.ItemsSource = peoples;
                }
            }
        }
        private async Task GetAllUser(string Text)
        {
            HttpClient httpClient = new HttpClient
            {
                BaseAddress = new System.Uri("http://localhost:60671/")
            };


            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            string str = $"api/values/getalluser/{NameMap.ChangeMap(Text)}";
            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(str);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                var res = await httpResponseMessage.Content.ReadAsAsync <string>();

                if (res != string.Empty)
                {
                    peoples = (JsonConvert.DeserializeObject <List <People> >(res));
                }
            }
        }