private void BtnSave_Click(object sender, RoutedEventArgs e) { try { if (txtIdProduct.Text == "") { Product product = new Product(); product.Name = txtProduct.Text; product.CreationDate = System.DateTime.Now; ProductBS productBs = new ProductBS(); product.Id = productBs.AddProduct(product); txtIdProduct.Text = product.Id.ToString(); MessageBox.Show("Produto " + product.Name + " ID " + product.Id + "Salvo com sucesso"); } else { Product product = new Product(); product.Id = int.Parse(txtIdProduct.Text); product.Name = txtProduct.Text; product.CreationDate = System.DateTime.Now; ProductBS productBs = new ProductBS(); product.Id = productBs.EditProduct(product); MessageBox.Show("Produto " + product.Name + " ID " + product.Id + "Alterado com sucesso"); } } catch (Exception ex) { MessageBox.Show("ERRO: " + ex.Message); } }
public IActionResult Post([FromBody] Product model) { if (!ModelState.IsValid) { return(BadRequest("data is invalid")); } else { if (p.AddProduct(model) == true) { return(Ok()); } else { return(NotFound()); } } }