private async void btnLogin_Click(object sender, RoutedEventArgs e) { //var loginModel = new LoginModel() {Username = txtUserName.Text, Password = pwbPassword.Password}; HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://moggeapi.azurewebsites.net/"); //client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Helpers.CredentialHelper.Credential = Convert.ToBase64String(Encoding.UTF8.GetBytes(txtUserName.Text + ":" + pwbPassword.Password)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Helpers.CredentialHelper.Credential); var response = await client.GetAsync("api/user/getaccesslevel"); if (response.IsSuccessStatusCode) { var user = JsonConvert.DeserializeObject <UserModel>(await response.Content.ReadAsStringAsync()); if (user.IsAdmin) { var window = new AdminStartWindow(); window.DataContext = new AdminStartViewModel(user); window.Show(); this.Close(); } else { var window = new DriverWindow(); window.DataContext = new DriverViewModel(user); window.Show(); this.Close(); } } }
public void Vehicles() { var window = new AdminStartWindow(); window.DataContext = new AdminStartViewModel(new UserModel()); window.Show(); }