Make the current value subtract from the previous value

1

I'm trying to make a supply system, I need it to take the last km registered in the bank of a specific vehicle and be subtracted by the new one that will be inserted I'm trying to do this, but it does not show any error, but does not subtract . My Controller:

var teste_01 = ckm.ConsultaVeiculo(viewModel.NumCarroId);
var teste_02 = teste_01.OrderBy(a => a.Km).FirstOrDefault();
viewModel.Km = viewModel.Km - teste_02.Km;

And this is my query:

public IList<Veiculo> ConsultaVeiculo(int Ncarro)
    {
        string hql = "SELECT v FROM Veiculo v";
        IQuery query = session.CreateQuery(hql);
        return query.List<Veiculo>();
    }
    
asked by anonymous 11.12.2017 / 20:39

1 answer

1

First step is to adjust your query:

public IList<Veiculo> ConsultaVeiculo(int Ncarro)
{
    string hql = "SELECT v FROM Veiculo v";
    IQuery query = session.CreateQuery(hql);
    query.setParameter("id", Ncarro); // verificar se o identificador é "id"
    return query.List<Veiculo>();
}

In this way you will get the vehicle you want, then in your controller:

var carro = ckm.ConsultaVeiculo(viewModel.NumCarroId).FirstOrDefault(); 
viewModel.Km = viewModel.Km - carro.Km;
    
12.12.2017 / 02:54