I need only do an update on two fields of my model. In the get I pass a DTO to my App. The question is: When I go to do my update (verb put) do I need to load all the property or just the one I'm going to upgrade? Like this:
[Route("atualiza/{id}")]
public void AtualizaLiberacao(LiberacaoDTO libera,int id)
{
var lista = contexto.Liberacoes
.Where(l => l.IdOrcamento == id)
.Select(s =>
{
s.AutorizouReceberAtrazado = float.Parse(libera.AutorizouReceberAtrazado),
s.FlagLiberacao = 0
});
}
Only these fields will receive new values, others will not. And how do I pass the text that will be updated? The id ok, but the text. I put a LiberacaoDTO just as an example, but I can pass the text as a string, that's my doubt. In place of the object I can pass the text (string) to be modified. All this is only illustrative. Is it possible to pass two parameters through the URL, rather than just the id?
My service:
[AcceptVerbs("Put")]
public void putItensLiberacao(int id, [FromBody]string value)
{
}
EDIT1
[Route("atualiza/{id}")]
public void AtualizaLiberacao(LiberacaoDTO libera)
{
contexto.Liberacoes
.Where(l => l.IdOrcamento == libera.IdOrcamento)
.Select(s =>
{
s.AutorizouReceberAtrazado = libera.AutorizouReceberAtrazado;
s.FlagLiberacao = libera.FlagLiberacao;
});
}
Is the above form correct? And how is the route with the id? What will he serve for?
I think that's it:
[Route("atualiza/{id}/{value}")]
public void AtualizaLiberacao(int id, string value)
{
var lista = contexto.Liberacoes
.Where(l => l.IdOrcamento == id).ToList();
lista.ForEach(f =>
{
f.FlagLiberacao = 0;
f.AutorizouReceberAtrazado = value;
});
contexto.SaveChanges();
}