2
I have a database with a list of shows registered with location, date and time, but I need it to return me on the admin screen only the shows that will still happen instead of listing all shows (past and future), if you can help me I thank!
The code is like this:
public ActionResult Index()
{
var model = new EventosViewModel();
foreach (var evento in _db.Evento.ToList())
{
List<DiaEventoAssociadoViewModel> dias = new List<DiaEventoAssociadoViewModel>();
if (evento.Dias == null)
evento.Dias = _db.EventoDia.Where(e => e.EventoId == evento.EventoId).ToList();
foreach (var dia in evento.Dias)
{
dias.Add(new DiaEventoAssociadoViewModel
{
Entrada = dia.DataHoraInicio,
EventoId = dia.EventoId,
Saida = dia.DataHoraFim,
});
}
if (model.Eventos == null)
model.Eventos = new List<EventoViewModel>();
model.Eventos.Add(new EventoViewModel(evento)
{
Dias = dias
});
}
return View(model);
}
The answer depends on what would be an "events that have not yet happened" for your business. Try to improve your question, for example: "events that have not yet happened" are events where the Exit field is not filled or is null. With this example we can show how to add this filter to your query if applicable. If possible edit the question and add this information :-)
– Renan
Sorry Renan... I’m new both here at Stack and in the area.. I’m learning a lot still... edited the question! =)
– Eder Fleming
Now it’s clearer :-), @Victor Laio has already answered there rs. Now you need to accept the answer if it solves your problem so that the question is not open.
– Renan