private async void loginUser() { try { string URL = "http://localhost:3000/api/createaccount"; string userName = textBox1.Text; string email = textBox3.Text; string password = textBox2.Text; requestCreateAccount login = new requestCreateAccount(); login.nameclient = userName; login.email = email; login.password = password; using (var client = new HttpClient()) { var loginFuncionario = JsonConvert.SerializeObject(login); var content = new StringContent(loginFuncionario, Encoding.UTF8, "application/json"); var result = await client.PostAsync(URL, content); var contents = await result.Content.ReadAsStringAsync(); if (result.IsSuccessStatusCode) { responseCreateAccount myDeserializedClass = JsonConvert.DeserializeObject <responseCreateAccount>(contents); MessageBox.Show(myDeserializedClass.msg, "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); if (myDeserializedClass.code == "2") { this.Close(); } } else { MessageBox.Show("Erro ao criar usuário!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch { MessageBox.Show("Ocorreu um erro inesperado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private async void delete() { try { string URL = "http://localhost:3000/api/category/" + idToDelete; using (var client = new HttpClient()) { UserPersist data = new UserPersist(); var token = data.getTokenUser(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); using (var response = await client.DeleteAsync(URL)) { if (response.IsSuccessStatusCode) { var dataResponse = await response.Content.ReadAsStringAsync(); responseCreateAccount myDeserializedClass = JsonConvert.DeserializeObject <responseCreateAccount>(dataResponse); MessageBox.Show(myDeserializedClass.msg, "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); GetAllCategorias(); } else { MessageBox.Show("Selecione uma Categoria para exluir!"); } } } } catch (ArgumentException e) { MessageBox.Show("Selecione uma Categoria para exluir!"); } }