public ParticipantsManagementViewModel BuildIndex(IDisplayPagination pagination,
                                                          bool allowHistory = false,
                                                          ParticipantsManagementViewModel.Filters?filters = null)
        {
            var currentConvention = Actor.ManagedConvention.ConventionId;
            var query             = Session.Query <ConventionEngagement>()
                                    .Include(x => x.ParticipantId)
                                    .Include(x => x.EventIds)
                                    .AsQueryable();

            if (allowHistory == false)
            {
                query = query.Where(x => x.ConventionId == currentConvention);
            }

            var engagements    = query.ToList();
            var wrapperFactory = new WrapperFactory(Session);

            var result = new ParticipantsManagementViewModel
            {
                filters     = filters,
                Pagination  = pagination,
                Engagements = wrapperFactory.Wrap(engagements)
            };

            return(result);
        }
        public ParticipantsManagementViewModel BuildSearchIndex(IDisplayPagination pagination, bool allowHistory = false, string searchWords = "")
        {
            if (searchWords.IsEmptyString())
            {
                return(new ParticipantsManagementViewModel());
            }

            var query = Session.Query <Participants_BySearchQuery.Result, Participants_BySearchQuery>()
                        .Include(x => x.ParticipantId)
                        .Include(x => x.ConventionId)
                        .Statistics(out var stats)
                        .Search(x => x.SearchText, searchWords).AsQueryable();

            if (allowHistory == false)
            {
                query = query.Where(x => x.ConventionId == Actor.ManagedConvention.ConventionId);
            }

            var results = query
                          .OrderBy(x => x.FullName)
                          .Skip(pagination.SkipCount)
                          .Take(pagination.ResultsPerPage)
                          .As <ConventionEngagement>()
                          .ToList();

            var wrapperFactory = new WrapperFactory(Session);
            var viewModel      = new ParticipantsManagementViewModel
            {
                Pagination = DisplayPagination.BuildForView(
                    stats.TotalResults,
                    pagination.SkipCount,
                    pagination.ResultsPerPage),
                Engagements = wrapperFactory.Wrap(results, false),
                filters     = new ParticipantsManagementViewModel.Filters()
            };

            return(viewModel);
        }