I made a WebAPI
that for Postman
I can make a CRUD
complete, but I created a Windows Forms C# pelo Visual Studio
and I have some problems.
I can give get
and all my data is fetched perfectly, but even giving a post
, apparently gives a Ok 200 do methodo Post
return, but nothing is created in my bank.
This is my controle
:
public IHttpActionResult Post([FromBody]PROJETO projeto)
{
var model = new ProjetoCriarEditarViewModel();
model.CriarProjeto = _projetoBO.CriarProjeto(projeto);
return Ok(model.CriarProjeto);
}
This is my method in C #.
private async void button1_Click(object sender, EventArgs e)
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:19832/");
PROJETO project = new PROJETO();
project.NOME = textBox1.Text;
project.DATA_INICIO = dateTimePicker1.Value;
project.DATA_PREVISTA = dateTimePicker2.Value;
project.TECNOLOGIA = textBox2.Text;
project.VALOR = Convert.ToDecimal(textBox3.Text);
project.STATUS_PROJETO = textBox4.Text;
project.ID_CLIENTE = Convert.ToInt32(textBox6.Text);
var resposta = await client.PostAsJsonAsync("/api/projetos/", project);
bool retorno = await resposta.Content.ReadAsAsync<bool>();
}
}