2
When consuming the update service, this error occurs:
The 'Datalib' Property on 'Release' could not be set to a 'System.Double' value. You must set this Property to a non-null value of type 'System.Single'
This mistake happens when
[Route("{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();
        }
I’ve already changed Model’s field to: double, float, Single and decimal And yet, the problem remains. As if the Entity or Lambda didn’t recognize the type. I know a lambda expression, it fetch all the records. Check it out, I just want to update two fields, a string and another byte. Can you do a lambda, to bring only the fields in question? I tried to give a select and it didn’t work, like:
var lista = contexto.Liberacoes
                    .Where(l => l.IdOrcamento == id)
                    //.ToList()
                    .Select(s => new Liberacao
                    {
                        FlagLiberacao = s.FlagLiberacao,
                        AutorizouReceberAtrazado = s.AutorizouReceberAtrazado
                    }).ToList();
When I do it the way above, it makes that mistake:
The Entity or Complex type 'Inet.AuthorizerService.Infra.Data.Context.Release' cannot be constructed in a LINQ to Entities query.
As I said, I tried changing the type and it still doesn’t work. I don’t have more resources.
EDIT1
In the get service I passed in DTO all to string and managed to fix this error. Well, I tried to do the same as below:
[Route("{id}/{value}")]
        public void AtualizaLiberacao(int id, string value)
        {
            var lista = contexto.Liberacoes
                        .Where(l => l.IdOrcamento == id)
                        .Select(libera => new LiberacaoDTO
                        {
                            TipoVenda = libera.TipoVenda,
                            IdOrcamento = libera.IdOrcamento,
                            Juros = libera.Juros.ToString(),
                            Entrada = libera.Entrada.ToString(),
                            Acrescimo = libera.Acrescimo.ToString(),
                            Desconto = libera.Desconto.ToString(),
                            Mensagem = libera.Mensagem,
                            DataLib = libera.DataLib.ToString(),
                            Vencimento = libera.Vencimento.ToString(),
                            Vendedor = libera.Vendedor,
                            Cliente = libera.Cliente,
                            Filial = libera.Filial
                        })
                        .ToList();
            lista.ForEach(f =>
            {
                f.FlagLiberacao = 0;
                f.AutorizouReceberAtrazado = "Testando";
            });
            contexto.SaveChanges();
        }
Well, the error disappeared, but I have two problems with it. It did not update and the value parameter I pass in URL is coming null. As list is Release and not DTO, I thought it could be done so. I stand by. I passed the value of Authorize as can be seen, as a literal and yet not updated. If someone can give me that strength, I wait.
EDIT2
I missed posting the service.
[RoutePrefix("api/Atualiza")]
    public class AtualizaController : ApiController
    {
        AutorizadorContext contexto = new AutorizadorContext();
        PedidoLiberacao liberacao = new PedidoLiberacao();
        [Route("{id}/{value}")]
        [AcceptVerbs("Put")]
        public void putItensLiberacao(int id, string value)
        {
            liberacao.AtualizaLiberacao(id, value);
        }
    }
In the string value parameter, there was a [Frombody], removed the parameter and is now coming with the correct value, but does not update.
EDIT3
I tried to do so:
var lib = new Liberacao();
            lib.AutorizouReceberAtrazado = value;
            lib.FlagLiberacao = 0;
            contexto.Entry(lib).State = EntityState.Modified;
            contexto.SaveChanges();
But when I save, it makes that mistake:
Store update, Insert, or delete statement affected an Unexpected number of Rows (0). Entities may have been modified or Deleted Since entities Were Loaded. See http://go.microsoft.com/fwlink/? Linkid=472540 for information on understanding and Handling optimistic concurrency exceptions.
Now I will do as Gabriel Colleta said
EDIT 4
List<LiberacaoDTO> lista = new List<LiberacaoDTO>();
            var lib = lista
                .Where(dto => dto.IdOrcamento == id)
                .Select(libera => new Liberacao
                {
                    TipoVenda = libera.TipoVenda,
                    IdOrcamento = libera.IdOrcamento,
                    Juros = float.Parse(libera.Juros),
                    Entrada = float.Parse(libera.Entrada),
                    Acrescimo = float.Parse(libera.Acrescimo),
                    Desconto = float.Parse(libera.Desconto),
                    Mensagem = libera.Mensagem,
                    DataLib = float.Parse(libera.DataLib),
                    Vencimento = float.Parse(libera.Vencimento),
                    Vendedor = libera.Vendedor,
                    Cliente = libera.Cliente,
                    Filial = libera.Filial,
                    FlagLiberacao = libera.FlagLiberacao,
                    AutorizouReceberAtrazado = libera.AutorizouReceberAtrazado
                }).ToList();
            lib.ForEach(l => 
            {
                l.AutorizouReceberAtrazado = value;
                l.FlagLiberacao = 0;
            });
            contexto.SaveChanges();
When a new of the Liberation class is made, the object is created as a whole, even if all properties are not initialized. Tip: Initialize properties that cannot be null in the constructor
– Alexandre Cavaloti
@Alexandrecavaloti, well, the fields float, double I’ll start in the class constructor with 0, that’s right?
– pnet
Yes, I imagine that, do the test after that change and if that’s what we formalize the solution.
– Alexandre Cavaloti
@Alexandrecavaloti, nothing expensive, did not work. Continues the error. I saw that in the Model these fields already have an attribute to start and even so I started the constructor with these values.
– pnet
@Alexandrecavaloti, I made an edition of a new form that I found. If you can give me a help, I thank you.
– pnet