private async void update(string id) { MessageBox.Show("DEBUG " + id); string Nome = textBox1.Text; string Email = textBox2.Text; string Senha = textBox3.Text; if (Nome == "") { MessageBox.Show("O campo nome é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Email == "") { MessageBox.Show("O campo Email é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (!Email.Contains("@")) { MessageBox.Show("digite um email válido", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha == "") { MessageBox.Show("O campo Senha é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } try { createUsuario update = new createUsuario(); update.nome = Nome; update.email = Email; update.passWorld = Senha; string URL = "http://localhost:3000/usuarios/" + id.ToString(); using (var client = new HttpClient()) { HttpResponseMessage responseMessage = await client.PutAsJsonAsync(URL, update); // MessageBox.Show("DEBUG " + client); if (responseMessage.IsSuccessStatusCode) { MessageBox.Show("Funcionário Alterado com suceso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); // this.Hide(); // var home = new Form1(); // home.Closed += (s, args) => this.Close(); // home.Show(); } else { MessageBox.Show("DEBUG" + responseMessage.ToString()); } } } catch { MessageBox.Show("Erro de conexão com o servidor", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private async void insertUser() { string Nome = textBox1.Text; string Email = textBox2.Text; string Senha = textBox3.Text; string SenhaConfirmada = textBox4.Text; if (Nome == "") { MessageBox.Show("O campo nome é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Email == "") { MessageBox.Show("O campo Email é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (!Email.Contains("@")) { MessageBox.Show("digite um email válido", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha == "") { MessageBox.Show("O campo Senha é obrigatório", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha.Length < 6) { MessageBox.Show("O campo Senha deve ter mais de 6 dígitos", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (Senha != SenhaConfirmada) { MessageBox.Show("As senhas não conferem", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string URL = "http://localhost:3000/usuarios"; try { createUsuario create = new createUsuario(); create.nome = Nome; create.email = Email; create.passWorld = Senha; using (var client = new HttpClient()) { var serializedUsuario = JsonConvert.SerializeObject(create); //MessageBox.Show("DEBUG " + serializedUsuario); var content = new StringContent(serializedUsuario, Encoding.UTF8, "application/json"); //MessageBox.Show("DEBUG " + content); var result = await client.PostAsync(URL, content); //MessageBox.Show("DEBUG " + result); if (result.IsSuccessStatusCode) { DialogResult dialogResult = MessageBox.Show("Usuário Cadastrado com sucesso", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Question); if (dialogResult == DialogResult.OK) { this.Close(); } } } } catch { this.Hide(); var erro = new ErroConexao(); erro.Closed += (s, args) => this.Close(); erro.Show(); } } }