I have a question here. I have an action that gets two parameters, two dates. this causes a list to be generated, except that in that list, the same item is being repeated. I wanted to be able to do a sum of money. To understand better, the system is garage management. Then I have the Vr (vehicle requisition - class), Mv (Vehicle Movement - Class), and Vehicle - Class.
Mv class
public int Id { get; set; }
public decimal CombustivelAbastecido { get; set; }
The Vr (Vehicle requisition) class has the vehicle. the report that I want to show receives the two dates, initial, and final, then it would show the vehicles requested in that period, a vehicle was requested more than once in that period, and had an Expenditure "X", so I wanted it to be more or less so;
IhavetheFuelclass,whichhasthevalueandthedescription.TheFuelSpend,wouldbethesumofallFuelsUsed,whichhasintheclassMv(VehicleMovement)
TheWayI'mDoing:
publicActionResultReportDate(DateTime?dataTime,DateTime?dataFim) {
ViewBag.dataInicial=dataInicio;ViewBag.dataFinal=dataFim;if(dataInicio==null&&dataFim==null){varvrDb=db.VrDb.Where(v=>v.DataSolicitacao>=dataInicio&&v.DataSolicitacao<=dataFim).OrderBy(v=>v.DataSolicitacao).ToList();returnView(vrDb);}else{varvrDb=db.VrDb.Where(v=>v.DataSolicitacao>=dataInicio&&v.DataSolicitacao<=dataFim&&v.Situacao==Situacao.Finalizado).OrderBy(v=>v.DataSolicitacao).ToList();vardata=dataInicio;vardataF=dataFim;vartot=db.VrDb.Sum(v=>v.Mv.Consumo);//MostraoTotalgastoif(tot==0){ViewBag.Total="0";
}
else
{
ViewBag.Total = tot;
}
var abastecido = db.VrDb.Sum(v => v.Mv.CombustivelAbastecido);
if (abastecido == 0)
{
ViewBag.Abastecido = "0";
}
else
{
ViewBag.Abastecido = abastecido;
}
var TotalValorEmDinheiro = db.VrDb.Sum(v => v.Veiculo.Combustivel.Preco * v.Mv.CombustivelAbastecido);
if (TotalValorEmDinheiro == 0)
{
ViewBag.TotalValorEmDinheiro = "0";
}
else
{
ViewBag.TotalValorEmDinheiro = TotalValorEmDinheiro;
}
return View(vrDb);
//return RedirectToAction("RelatorioTotalPorData", vrDb);
}
}
This way it's bringing me this way
In other words, it is repeating the same vehicle. Without counting the expense, it is bringing me the same thing.