0
I’m trying to catch the last mile registered on the seat of a specific vehicle, but it brings me all the miles and not a specific vehicle.
My Controller:
var Rota = ckm.ConsultaProduto(viewModel.NumCarroId);
var maiorRota = Rota.OrderByDescending(c => c.Km).First();
if (maiorRota != null && viewModel.Km < maiorRota.Km)
// Aqui se não tiver valor para fazer comparação (maiorRota != null), ele ira registrar.
// Ele ira fazer a comparação e ira salvar se estiver de acordo(viewModel.Km < maiorRota.Km).
{
ModelState.AddModelError("Km_Atual.Invalido", "A quilometragem precisa ser maior que a anterior");
}
My query where you get the bank information:
public IList<Abastecimento> ConsultaProduto(int Id)
{
string hql = "SELECT a FROM Abastecimento a";
IQuery query = session.CreateQuery(hql);
return query.List<Abastecimento>();
}
I’m trying to get him to take the last mile on the bench and then compare it to the current one, if it’s bigger it will register, if there’s no error
Guilherme you need to use the Id parameter as a filter in the Product Query method. Example: string hql = "SELECT Campox, Campoy FROM Abastecimento WHERE Campofkdeveiculo = " + Id;
– Renan
I’m new to c#. net com mvc, I don’t know how to apply in hql the option of it interfering in my view, I usually apply the Where in the controller and use the viewmodel
– Guilherme Padovam