Controller:
public ActionResult SelectPlaats()
{
var one = repository.GetAllReserveringen.Where(x => x.StartDatum >= x.StartDatum
&& x.StartDatum <= x.EindDatum).Select(p => p.Plaats);
var two = repository.GetAllPlekken.Select(p => p.Plaatsnummer);
ViewBag.vrijeplekken = two.Except(one).ToList();
return View(repository.GetAllPlekken);
}
View:
@using Camping.Domain.Entities
@model IEnumerable<Plek>
@{
ViewBag.Title = "Beschikbare campingplekken";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="panel panel-default">
<div class="panel-heading">
<h3>Overzicht van alle klanten</h3>
</div>
<div class="panel-body">
<table class="table table-striped table-condensed table-bordered">
<tr>
<th>Plaatsnummer</th>
<th>Veldnaam</th>
<th>Type</th>
<th>Vierkante meter</th>
<th>Amp</th>
<th>Wifi</th>
<th>Water</th>
<th>Riool</th>
<th>CAI</th>
<th>PPN</th>
<th>Seizoenplek</th>
<th class="text-center">Reserveren</th>
</tr>
@foreach (var item in Model.Where(x => x.Plaatsnummer == ViewBag.vrijeplekken))
{
<tr>
<td>@item.Plaatsnummer</td>
<td>@item.Veldnaam</td>
<td>@item.Type</td>
<td>@item.Vierkantemeter</td>
<td>@item.Amp</td>
<td>@item.Wifi</td>
<td>@item.Water</td>
<td>@item.Riool</td>
<td>@item.CAI</td>
<td>@item.PPN</td>
<td>@item.Seizoenplek</td>
<td class="text-center">
@using (Html.BeginForm("SelectPlek", "Reservering"))
{
@Html.Hidden("Id", item.Plaatsnummer)
<input type="submit"
class="btn btn-default btn-xs"
value="Reserveren" />
}
</td>
</tr>
}
</table>
</div>
</div>
So we have the Model with all the campingsides + details my camping application has. But I only want to display in this view the free campingspots.
I extracted all the free campingsides from my database and put them in my Viewbag.vrijeplekken which holds a list of the sidenumbers (Plaatsnummer).
I can't figure out how to get a table with only the free campingsidenumbers but with the details all the campingsides have.
I hope anyone can help me out. Thanks in advance!