This is part of my timetable code
Two questions :
-
How can I prevent having to loop through the times, and then the roombookings to check if it exists in the given time slot. Is there a way of just saying “for this time, is there a match(s) from this list and what is its Id”
-
Is there anyway I can set the outer td to class bgred, rather than a span. (Note that there may be multiple bookings in a timeslot, hence having the td out of the foreach loop.)
<tr>
<th></th>
@for (int i = 9; i <= 17; i++)
{
<th>@i:00</th>
}
</tr>
@foreach (var RoomNo in ViewBag.Rooms)
{
<tr>
<th>@RoomNo</th>
@for (int i = 9; i <= 17; i++)
{
<td>
@foreach (var roombooking in ViewBag.RoomBookings)
{
DateTime DateCheckStart = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":00");
DateTime DateCheckEnd = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":59");
if (DateCheckStart < roombooking.EndDateTime && DateCheckEnd > roombooking.StartDateTime && roombooking.RoomNo == RoomNo)
{
<span class="bgred"> @roombooking.RentalNo</span>
}
}
</td>
}
</tr>
}
Try something like this.
What this does is it loops through onlyt he