I have the following lamba query that seems to always return all records even when the int? status pamameter is not null and valid. Anyone know why is the Enum filter not being honored? Thanks for reading!
public ActionResult GetArrivals(int facilityId, int? status)
{
var registrationList = db.Registrations
.Where(f => f.Facility.Id == facilityId)
.Where(a => a.ArrivalDateTime >= DateTime.Today)
.OrderBy(ln => ln.User.LastName)
.OrderBy(fn => fn.User.FirstName);
if (status.HasValue)
{
UrgentCareWaitWeb.Models.RegistrationStatus statusValue;
if (Enum.TryParse(status.Value.ToString(), out statusValue) == true)
{
registrationList
.Where(s => s.Status == statusValue);
}
}
// Project query to view
var pview = registrationList.Select(r => new PatientRegistrationsView()
{
ArrivalId = r.Id,
UserId = r.User.UserId,
UserName = r.User.UserName,
FirstName = r.User.FirstName,
LastName = r.User.LastName,
PrimaryPhone = r.User.PrimaryPhone,
SecondaryPhone = r.User.SecondaryPhone,
ArrivalDateTime = r.ArrivalDateTime,
PatientDataformId = r.PatientDataformId,
RegistrationStatus = r.Status,
});
//if (Request.IsAjaxRequest())
// return PartialView("_PatientRegistrations", model);
return View(pview);
}