Doubt with service rest and with put verb

0

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();

    }
    
asked by anonymous 14.09.2017 / 14:57

1 answer

2
  

When I go to do my update (verb put) I need to load all   the properties or just the one I'm going to upgrade?

No, you can just upload what you are going to use.

[Route("atualiza/{id}/{value1}/{value2}")]
        public void AtualizaLiberacao(int value1, float value2, int id)
        {
            var lista = contexto.Liberacoes
                .Where(l => l.IdOrcamento == id)
                .Select(s =>
                {
                    s.AutorizouReceberAtrazado = value2,
                    s.FlagLiberacao = value1
                });
        }
  

Can you pass two parameters through the URL, instead of just the id?

Yes, you can spend as many seats as you want. example: [Route("atualiza/{id}/{value}")]

That?

    
14.09.2017 / 15:19