public ActionResult ListCavesForFilters(TableRequestModel request, FilteredCavesViewModel model)
        {
            request.PageSize = request.PageSize ?? 10;
            //var caves = db.Caves;
            IQueryable<Cave> caves = db.Caves;
            //var mainPredicate = PredicateBuilder.True<Cave>();
            if(model.HideCodelessItems)
            {
                caves = caves.Where(p => p.SasaCode != null);
            }
            if(!string.IsNullOrEmpty(model.SearchText))
            {
                caves = caves.Where(p => p.Name.Contains(model.SearchText) || p.Description.Contains(model.SearchText));
            }
            if(!string.IsNullOrEmpty(model.SelectedCaveAttributes))
            {
                //var attributePredicate = PredicateBuilder.True<Cave>();
                var caveAttributeList = model.SelectedCaveAttributes.Split(',').ToList();
                foreach (var item in caveAttributeList.Where(p => p != "null"))
                {
                    caves = caves.Where(p => p.CaveAttributes.Any(x => x.CaveAttributeId == item));
                    //attributePredicate = attributePredicate.Or(p=> p.CaveAttributes.Contains(new CaveAttribute(){CaveAttributeID = item}));
                }
                //mainPredicate = mainPredicate.And(attributePredicate);
            }
            if (!string.IsNullOrEmpty(model.SelectedCaveStatuses))
            {
                var caveStatusList = model.SelectedCaveStatuses.Split(',').ToList();

                foreach (var item in caveStatusList.Where(p=> p != "null"))
                {
                    caves = caves.Where(p=> p.CaveStatuses.Any(x=> x.CaveStatusId == item ));
                    //statusPredicate = statusPredicate.Or(p => p.CaveStatuses.Any(x=> x.CaveStatusID == item));
                }
                //caves = caves.Where(statusPredicate);
                //mainPredicate = mainPredicate.And(statusPredicate);
            }
            if (!string.IsNullOrEmpty(model.SelectedExplorationStatus))
            {
                caves = caves.Where(p => p.ExplorationStatusId == model.SelectedExplorationStatus);
            }
            if (!string.IsNullOrEmpty(model.SelectedLocationStatus))
            {
                //mainPredicate.And(p => p.LocationStatusID == model.SelectedLocationStatus);
                caves = caves.Where(p => p.LocationStatusId == model.SelectedLocationStatus);
            }

            //if (!String.IsNullOrEmpty(model.SelectedCustomerId))
            //{
            //	orders = orders.Where(o => o.CustomerID == model.SelectedCustomerId);
            //}
            //caves = caves.Where(mainPredicate);

            //var mycaves = caves.ToList();
            return TableResult.From(caves).Build<CaveFilterTable>(request);
        }
        public ActionResult Index()
        {
            var filteredCavesVM = new FilteredCavesViewModel();
            var LookupRepository = new LookupRepository(db);
            filteredCavesVM.HideCodelessItems = true;
            filteredCavesVM.ExplorationStatusSelectList = new SelectList(LookupRepository.ExplorationStatuses, "ExplorationStatusID", "Description");
            filteredCavesVM.LocationStatusSelectList = new SelectList(LookupRepository.LocationStatuses, "LocationStatusID", "Description");
            //filteredCavesVM.ProvincesSelectList = new SelectList(LookupRepository.ProvinceList, "ProvinceID", "Description");
            filteredCavesVM.CaveStatusSelectList = new SelectList(LookupRepository.CaveStatuses, "CaveStatusID", "Description");
            filteredCavesVM.CaveAttributeSelectList = new SelectList(LookupRepository.CaveAttributes, "CaveAttributeID", "Description");

            filteredCavesVM.Caves =db.Caves.Include(c => c.ExplorationStatus).Include(c => c.LocationStatus).Include(c => c.Province).Take(10);
            return View(filteredCavesVM);
        }