public CaseInsurance GetActiveInsuranceAtDate(DateTime refDate) { var insurances = Insurances .Where(x => x.DatePlanEffective.GetValueOrDefault(DateTime.MinValue) <= refDate && x.DatePlanTerminated.GetValueOrDefault(DateTime.MaxValue) >= refDate) .OrderBy(x => x.DatePlanTerminated) .OrderByDescending(x => x.DatePlanEffective) .ToList(); return(insurances.FirstOrDefault()); }
public List <CaseInsurance> GetActiveInsurance(DateTime StartDate, DateTime EndDate) { var insurances = Insurances .Where(x => x.DatePlanEffective.GetValueOrDefault(DateTime.MinValue) <= EndDate && x.DatePlanTerminated.GetValueOrDefault(DateTime.MaxValue) >= StartDate) .OrderBy(x => x.DatePlanTerminated) .OrderByDescending(x => x.DatePlanEffective) .ToList(); return(insurances); }