2
I made a WebAPI
that by Postman
I can make a CRUD
but I created a Windows Forms C# pelo Visual Studio
and I’m having some problems.
I can give a get
and all my data is searched perfectly, only that while giving a post
, apparently of a return Ok 200 do methodo Post
, 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 C method#.
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>();
}
}
just to be sure, your
_projetoBO.CriarProjeto
is giving commit at the end of the process?– rLinhares
Yes. I can post by Postman using the api and it creates perfectly in the database of my application. And I can also use "_projectBO.Criar projeto" in every app.
– joaop.mr
Put the [Httppost] attribute on top of your Controller?
– perozzo
I did not put it because he understands that it is a Post by the name of the method. So in this case it makes no difference.
– joaop.mr
@joaop.mr But did you test with the attribute? Do the post with the attribute through the code and not from Postman?
– perozzo
I tested for rs and nothing.
– joaop.mr
if already debugged? another thing inside this code: Create project?
– novic
I have debugged it. It returns the OK 200 post method. As if it had saved it. However it does not save.
– joaop.mr
Creating project is my method in the business rules that leads to the repository. Otherwise, I use the Entity Framework.
– joaop.mr
You have to debug the code from the repository!
– novic
But I can send by Postman. And I can also save in the application. I will anyway.
– joaop.mr