private void OK_Click(object sender, RoutedEventArgs e) { isChosen = true; if (ItemBox.SelectedIndex != -1) { chosenToken = list[ItemBox.SelectedIndex]; } else { return; } Close(); }
public MainWindow(TokensToView tokens) { try { httpClient = new HttpClient() { DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token) }, BaseAddress = new Uri(@"http://localhost:49837/api/") }; InitializeComponent(); GetProfile(); Endtime.Content = tokens.End_time; search = new Search(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void Sign_Click(object sender, RoutedEventArgs e) { Sign.IsEnabled = false; Continue.IsEnabled = false; TokensToView token = null; try { using (HttpClient httpClient = new HttpClient()) using (HttpResponseMessage responseMessage = await httpClient.GetAsync(uri + $"Login/?login={Login_Textbox.Text}&password={Password_Textbox.Password}")) using (Stream stream = await responseMessage.Content.ReadAsStreamAsync()) using (StreamReader reader = new StreamReader(stream)) { token = JsonConvert.DeserializeObject <TokensToView>(reader.ReadToEnd()); } } catch (Exception ex) { Sign.IsEnabled = true; Continue.IsEnabled = true; MessageBox.Show(ex.Message); return; } if (token == null) { Sign.IsEnabled = true; Continue.IsEnabled = true; MessageBox.Show("You entered invalid data"); return; } var window = new MainWindow(token); window.Show(); this.Close(); }