This is my DB (part of it):
Vehicule table :
Matv string primary ;
cCode int foreign key references city,
// some other columns
Indisponible(unavailable) table:
idin int primary,
from date
to date
idv string foreign key references Matv in vehicule table.
One vehicule can have many unavailable dates.
This is my search method:
public ActionResult search(int citycode, string from, string to)
{
DateTime dd1 = Convert.ToDateTime(from);
DateTime df1 = Convert.ToDateTime(to);
var model = (from p in entity.vehicule
join y in entity.indisponible on p.Matv equals y.idv
where p.cCode == citycode && ( dd1 > y.Df && df1 < y.Dd )
select p).ToList();
return View(model);
}
This search query will allow me to find all avaible cars in the city between to the dates from and to.
So to do this i have to check that the date chosen by the user is not in the unavailable table.
For example this car is unvailable
From 01/04/201 to 26/04/2012 and From 01/05/2012 to 09/05/2012.
So if user make search From 28/04/2012 to 30/04/2012 this car has to be shown
Else if he make search From 28/04/2012 to 03/05/2012 this car will not be showed in search result.
But something is wrong, it never shows any results. Can anyone help me to fix it ?
That
whereapplies to each row. It cannot consider multiple rows at the same time to determine availability. But it should… any indisponible record that is in our range should filter the car completely.This might be closer to what you want:
All returns true if every record meets that criteria and it returns true when the source is empty.
An indisponible record shouldn’t filter our car if if starts after our range or if it ends before our range. If all the indisponible records are such, then we keep the car.