private void Button_Click(object sender, RoutedEventArgs e) { // Login var username = tbxUsername.Text; var password = pwdBox.Password; if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) { // return error message LoginFailedSetStyle("Username & password must be filled"); return; } var httpClient = new HttpClient { BaseAddress = new Uri(HttpClientHelper.ApiUrl + "Login"), DefaultRequestHeaders = { Accept = { new MediaTypeWithQualityHeaderValue("application/xml") } } }; // Post login info var response = httpClient.GetStringAsync(string.Format($"?USERNAME={username}&PASSWORD={password}")).Result; if (response != null) { var doc = new XmlDocument(); doc.LoadXml(response); string jsonText = JsonConvert.SerializeXmlNode(doc); var jsonLogin = JsonConvert.DeserializeObject <JsonLogin>(jsonText); if (string.IsNullOrEmpty(jsonLogin.Page?.Rows?.Row[0].SessionKey)) { // Error LoginFailedSetStyle(jsonLogin.Page.Error.ErrorMessage); return; } // Set session Key and user id in settings Settings.Default.SessionKey = jsonLogin.Page.Rows.Row[0].SessionKey; Settings.Default.Save(); // Switch window var mainWindow = new _mainFrame(); App.Current.MainWindow = mainWindow; //this.Close(); this.Visibility = Visibility.Hidden; mainWindow.Show(); } }
public LoginWindow() { var jsonLogin = HttpClientHelper.Get <JsonLogin>("ValidateSession"); if (jsonLogin.Page?.Error == null) { // Switch window var mainWindow = new _mainFrame(); App.Current.MainWindow = mainWindow; //this.Close(); this.Visibility = Visibility.Hidden; mainWindow.Show(); return; } InitializeComponent(); }