// GET: Keepers public ActionResult Index(SearchModel search) { using (var db = new ZooDbContext()) { var model = new IndexModel(search); if (search.HasQuery) { using (var session = MvcApplication.DocumentStore.OpenSession()) { model.Keepers = session.Query<KeeperIndex.Result, KeeperIndex>() .OrderBy(x => x.KeeperId) .Search(x => x.Search, model.Search.Query) .AsProjection<KeeperViewModel>() .ToPagedList(model.Search.Page, model.Search.Size); } } else { model.Keepers = db.Keepers .OrderBy(x => x.Id) .Select(x => new KeeperViewModel { KeeperId = x.Id, FirstName = x.FirstName, LastName = x.LastName, Sex = x.Sex }).ToPagedList(model.Search.Page, model.Search.Size); } return View(model); } }
public IndexModel(SearchModel search) { Search = search; Keepers = new PagedList<KeeperViewModel>(Enumerable.Empty<KeeperViewModel>(), 1, 10); }