Guest User

Untitled

a guest
Dec 13th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. var Rota = ckm.ConsultaProduto(viewModel.NumCarroId);
  2.  
  3. var maiorRota = Rota.Where(p => p.Id == viewModel.NumCarroId).OrderByDescending(c => c.Km).First();
  4.  
  5. if (maiorRota != null && viewModel.Km < maiorRota.Km)
  6. // Aqui se não tiver valor para fazer comparação (maiorRota != null), ele ira registrar.
  7. // Ele ira fazer a comparação e ira salvar se estiver de acordo(viewModel.Km < maiorRota.Km).
  8. {
  9. ModelState.AddModelError("Km_Atual.Invalido", "A quilometragem precisa ser maior que a anterior");
  10. }
  11.  
  12. public IList<Abastecimento> ConsultaProduto(int Id)
  13. {
  14. string hql = "SELECT a FROM Abastecimento a";
  15. IQuery query = session.CreateQuery(hql);
  16. return query.List<Abastecimento>();
  17. }
Add Comment
Please, Sign In to add comment