I have following Linq query. What I want is if I do search for a particular year, I should get corresponding records of that year. Else just show records of current year. Same way searchtext has also to be done.
public ActionResult Search(string searchtext, int? year)
{
string selyear = year.ToString();
string curyear = (DateTime.Now.Year).ToString();
hdms = from t in db.HOLIDAY
where
(year == null || t.DOH.StartsWith(selyear)) &&
(searchtext == "" || t.HOLIDAY_NAME == searchtext)
select new HOLIDAYDETAILS
{
DOH = t.DOH,
};
....
}
I want to satisfy this also if (year == null) then t.DOH.StartsWith(curyear) and
if (searchtext == "") then t.HOLIDAY_NAME != "Sunday" && t.HOLIDAY_NAME != "Saturday".
Also If both are null at the same time, both conditions should be satisfied together.
How can I give this one too on the above where clause?