public virtual PagedList <StudyField> GetStudyFields(LocationResourceParameter locationResourceParameter)
        {
            var collectionBeforePaging = _context.StudyFields
                                         .OrderBy(a => a.Field).AsQueryable();

            if (!string.IsNullOrEmpty(locationResourceParameter.Name))
            {
                //trim & ignore casing
                var nameForWhereClause = locationResourceParameter.Name.Trim().ToLowerInvariant();
                collectionBeforePaging = collectionBeforePaging
                                         .Where(a => a.Field.ToLowerInvariant() == nameForWhereClause);
            }

            if (!string.IsNullOrEmpty(locationResourceParameter.SearchQuery))
            {
                //trim & ignore casing
                var searchQueryorWhereClause = locationResourceParameter.SearchQuery.Trim().ToLowerInvariant();

                collectionBeforePaging = collectionBeforePaging
                                         .Where(a => a.Field.ToLowerInvariant().Contains(searchQueryorWhereClause));
            }

            return(PagedList <StudyField> .Create(collectionBeforePaging,
                                                  locationResourceParameter.PageNumber, locationResourceParameter.PageSize));
        }
示例#2
0
        public IActionResult GetLocation(LocationResourceParameter locationResourceParameter)
        {
            CreateResourceUri cru = new CreateResourceUri(this._urlHelper);

            var locationsfromRepo = _locationRepository.GetLocations(locationResourceParameter);

            var previousPageLink = locationsfromRepo.HasPrevious ?
                                   cru.CreateUri(locationResourceParameter, ResourceUriType.PreviousPage, "GetLocations") : null;

            var nextPageLink = locationsfromRepo.HasNext ?
                               cru.CreateUri(locationResourceParameter, ResourceUriType.NextPage, "GetLocations") : null;

            var paginationMetadata = new
            {
                totalcount       = locationsfromRepo.TotalCount,
                pageSize         = locationsfromRepo.PageSize,
                currentPage      = locationsfromRepo.CurrentPage,
                totalPages       = locationsfromRepo.TotalPages,
                previousPageLink = previousPageLink,
                nextPageLink     = nextPageLink
            };

            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));
            var locations = Mapper.Map <IEnumerable <LocationViewModel> >(locationsfromRepo);

            return(Ok(locations));
        }
示例#3
0
        public string CreateUri(LocationResourceParameter locationResourceParameter, ResourceUriType type, string linkValue)
        {
            switch (type)
            {
            case ResourceUriType.PreviousPage:
                return(_urlHelper.Link(linkValue,
                                       new
                {
                    searchQuery = locationResourceParameter.SearchQuery,
                    name = locationResourceParameter.Name,
                    pageNumber = locationResourceParameter.PageNumber - 1,
                    pageSize = locationResourceParameter.PageSize
                }));

            case ResourceUriType.NextPage:
                return(_urlHelper.Link(linkValue,
                                       new
                {
                    searchQuery = locationResourceParameter.SearchQuery,
                    name = locationResourceParameter.Name,
                    pageNumber = locationResourceParameter.PageNumber + 1,
                    pageSize = locationResourceParameter.PageSize
                }));

            default:
                return(_urlHelper.Link(linkValue,
                                       new
                {
                    searchQuery = locationResourceParameter.SearchQuery,
                    name = locationResourceParameter.Name,
                    pageNumber = locationResourceParameter.PageNumber,
                    pageSize = locationResourceParameter.PageSize
                }));
            }
        }