public async Task<string> LoginAsync(string url)
        {
            var login = new Dictionary<string, object>
            {
                {"username",usernameTb.Text},
               
                {"password",password_tb.Text}
            };

            string payloadFood = JsonConvert.SerializeObject(login);
            var httpContent = new StringContent(payloadFood, Encoding.UTF8, "application/json");
            var httpResponse = await _httpClient.PostAsync(url, httpContent);
            string status = (httpResponse.StatusCode == HttpStatusCode.Created).ToString();
            var response = await httpResponse.Content.ReadAsStringAsync();

            switch (httpResponse.StatusCode) {
                case HttpStatusCode.OK:
                    var loginResponse = JsonConvert.DeserializeObject<LoginResponse>(response);
                    TokenContainer.Token = loginResponse.Token;
                    Main_Window mainwindow = new Main_Window();
                    mainwindow.Show();
                    this.Close();
                    break;
                case HttpStatusCode.Unauthorized:
                    MessageBox.Show("Nieprawidłowe dane");
                    
                    break;
            }

            return response;
        }
Example #2
0
        private void back_b_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Main_Window window = new Main_Window();

            window.Show();
        }
        private void b_cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Main_Window mainwindow = new Main_Window();

            mainwindow.Show();
        }