I'm trying to get a specific car between dates, because it works in periods, but I need to get the element ID, I do not know if I would have to apply some other query or include it, the database I use is SQL, case there is doubt
I want to do would be as follows:
SELECT * FROM Abastecimento a WHERE NumCarroId = 1013 AND DtAbastecido BETWEEN '2017-07-01'AND '2017-07-30';
Being in 1013
I wanted it to take from the textbox of my view
My HQL returns me the date period:
public IList<Abastecimento> ConsultaPeriodo(DateTime dataInicio, DateTime dataFinal)
{
string hql = "SELECT a FROM Abastecimento a WHERE a.DtAbastecido BETWEEN :dataInicial AND :dataFinal";
IQuery query = session.CreateQuery(hql)
.SetParameter("dataInicial", dataInicio)
.SetParameter("dataFinal", dataFinal);
return query.List<Abastecimento>();
}
And my controller that uses this query:
public ActionResult AbastecimentoPeriodo(DateTime dataInicio, DateTime dataFinal, int? pagina, Boolean? gerarPDF, AbastecimentoModel viewModel)
{
var data = ckm.ConsultaPeriodo(dataInicio,dataFinal);
ViewBag.dataInicio = dataInicio;
ViewBag.dataFinal = dataFinal;
var periodo = data.Where(i => i.DtAbastecido >= dataInicio && i.DtAbastecido <= dataFinal).OrderBy(p => p.DtAbastecido).ToList<Abastecimento>();
int paginaQdteRegistros = 25;
int paginaNumeroNavegacao = (pagina ?? 1);
return View(data.ToPagedList(paginaNumeroNavegacao, paginaQdteRegistros));
}