Пример #1
0
        private void btnMainSubmitBan_Click(object sender, RoutedEventArgs e)
        {
            Login SqlLogin = new Login();

            SqlLogin.ShowDialog();
            {
                tAuthenticationResponse authenticationResult = new Classes.tAuthenticationResponse();

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:55071/");

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    tCredential credential = new Classes.tCredential();
                    credential.Username = SqlLogin.txtSqlUserName.Text;
                    credential.Password = SqlLogin.txtSqlPassword.Password;

                    string serializedBan = JsonConvert.SerializeObject(credential);

                    StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json");


                    HttpResponseMessage response = client.PostAsync("A3Bans/LogIn", content).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        string strResponse = response.Content.ReadAsStringAsync().Result;
                        authenticationResult = JsonConvert.DeserializeObject <tAuthenticationResponse>(strResponse);
                    }
                }

                if (authenticationResult.AuthenticationSuccess)
                {
                    this.Hide();
                    SubmitBan SubBan = new SubmitBan();
                    SubBan.ShowDialog();
                }
                else
                {
                    MessageBox.Show(authenticationResult.Message);
                }
            }
        }
Пример #2
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            {
                Login SqlLogin = new Login();
                SqlLogin.ShowDialog();
                {
                    tAuthenticationResponse authenticationResult = new Classes.tAuthenticationResponse();

                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri("http://localhost:55071/");

                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                        tCredential credential = new Classes.tCredential();
                        credential.Username = SqlLogin.txtSqlUserName.Text;
                        credential.Password = SqlLogin.txtSqlPassword.Password;

                        string serializedBan = JsonConvert.SerializeObject(credential);

                        StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json");


                        HttpResponseMessage response = client.PostAsync("A3Bans/LogIn", content).Result;

                        if (response.IsSuccessStatusCode)
                        {
                            string strResponse = response.Content.ReadAsStringAsync().Result;
                            authenticationResult = JsonConvert.DeserializeObject <tAuthenticationResponse>(strResponse);
                        }
                    }

                    if (authenticationResult.AuthenticationSuccess)
                    {
                        this.Hide();
                        Classes.tBan bans = new tBan();
                        using (var client = new HttpClient())
                        {
                            //client.BaseAddress = new Uri("http://192.223.30.108:55071/");
                            client.BaseAddress = new Uri("http://localhost:55071/");

                            client.DefaultRequestHeaders.Accept.Clear();
                            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                            HttpResponseMessage response = null;
                            try
                            {
                                tBan ban = new Classes.tBan();
                                ban.GuidOrIP = schGUID.Text;

                                string serializedBan = JsonConvert.SerializeObject(ban);

                                StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json");

                                response = client.PostAsync("A3Bans/deleteBan", content).Result;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Player ban does not exist");
                            }


                            if (response.IsSuccessStatusCode)
                            {
                                string strResponse = response.Content.ReadAsStringAsync().Result;
                                try
                                {
                                    banReponse = JsonConvert.DeserializeObject <Classes.tBan>(strResponse);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(authenticationResult.Message);
                    }
                }
            }
        }