public async Task <IPagedList <CaseForm> > SearchCaseFormsAsync(CaseFormParameters caseFormParams)
        {
            // Paging & Sorting Option #1: Using specification pattern
            //var allCaseFormsSpec = new CaseFormWithSubmittedBySpecification(args.PageIndex * args.PageSize, args.PageSize);
            //return await GetAsync(allCaseFormsSpec);

            // Paging & Sorting Option #2: Using PagedList<> instance
            var query = Table.Include(c => c.SubmittedBy);

            // Building filter criteria
            var filterList = new List <Expression <Func <CaseForm, bool> > >();

            if (!String.IsNullOrEmpty(caseFormParams.CaseNumber))
            {
                filterList.Add(c => c.CaseNumber == caseFormParams.CaseNumber);
            }

            if (caseFormParams.HideTransmitted)
            {
                filterList.Add(c => !c.TransferredToState);
            }

            // TODO: Remaining filter criteria ...

            if (!String.IsNullOrEmpty(caseFormParams.Search))
            {
                var searchString = caseFormParams.Search.Trim().ToLower();

                filterList.Add(c => c.CaseNumber.ToLower().Contains(searchString) ||
                               c.HearingDateTime.ToString().Contains(searchString) ||
                               c.PlaintiffName.ToLower().Contains(searchString) ||
                               c.SubmittedBy.FirstName.ToLower().Contains(searchString) ||
                               c.SubmittedBy.LastName.ToLower().Contains(searchString));

                // TODO: Remaining properties to search on ...
            }

            //query = query.Where(filterList);

            return(await PagedList <CaseForm> .CreateAsync(query, new PageSortArgs { PageIndex = caseFormParams.PageIndex, PageSize = caseFormParams.PageSize, SortColumn = caseFormParams.SortColumn, SortOrder = caseFormParams.SortOrder }, filterList));
        }
예제 #2
0
        public async Task <IPagedList <CaseFormDto> > SearchCaseForms(CaseFormParameters caseFormParams)
        {
            _logger.LogInformation(LoggingEvents.ListItems, "Listing case forms from database based on paging & searching arguments.");

            var caseFormPagedList = await _caseFormRepo.SearchCaseFormsAsync(caseFormParams);

            _logger.LogInformation(LoggingEvents.ListItems, $"Retrieved {caseFormPagedList.TotalCount} case forms from database.");

            // TODO: better mapping solution between PagedList<TSource> and PagedList<TDestination> ...
            //      ... maybe create a PagedListConverter ??
            var caseFormDtos = _mapper.Map <IEnumerable <CaseFormDto> >(caseFormPagedList.Data);

            var caseFormDtosPagedList = new StaticPagedList <CaseFormDto>(
                caseFormDtos,
                caseFormPagedList.TotalCount,
                caseFormPagedList.PageIndex,
                caseFormPagedList.PageSize,
                caseFormPagedList.SortColumn,
                caseFormPagedList.SortOrder);

            return(caseFormDtosPagedList);
        }
예제 #3
0
        public async Task <ActionResult <IPagedList <CaseFormDto> > > Get([FromQuery] CaseFormParameters requestParams)
        {
            var caseForms = await _caseFormService.SearchCaseForms(requestParams);

            return(Ok(caseForms));
        }