Esempio n. 1
0
        public ActionResult <IEnumerable <Product> > GetProducts([FromQuery] ResourceParameters resourceParameters)
        {
            var products     = _repository.GetProductsPage(resourceParameters);
            var cResourceUri = new CreateResourceUri(_urlHelper);


            var previousPageLink = products.HasPrevious ?
                                   cResourceUri.CreateProductResourceUri(resourceParameters,
                                                                         ResourceUriType.PreviousPage, "GetProducts") : null;

            var nextPageLink = products.HasNext ?
                               cResourceUri.CreateProductResourceUri(resourceParameters,
                                                                     ResourceUriType.NextPage, "GetProducts") : null;

            var paginationMetadata = new
            {
                totalCount  = products.TotalCount,
                pageSize    = products.PageSize,
                currentPage = products.CurrentPage,
                totalPages  = products.TotalPage,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("X-Pagination",
                                 Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));
            return(Ok(_mapper.Map <IList <Product>, IList <ProductViewModel> >(products)));
        }
Esempio n. 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));
        }
Esempio n. 3
0
        public static List <LinkDto> Create(
            CreateResourceUri createResourceUri,
            int[] ids,
            ResourceParametersBase resourceParameters,
            bool hasPrevious,
            bool hasNext)
        {
            var links = new List <LinkDto>
            {
                new LinkDto(createResourceUri(
                                ids,
                                resourceParameters,
                                ResourceUriType.Current),
                            "self",
                            HttpMethods.Get)
            };

            if (hasPrevious)
            {
                links.Add(new LinkDto(createResourceUri(
                                          ids,
                                          resourceParameters,
                                          ResourceUriType.PreviousPage),
                                      "previousPage",
                                      HttpMethods.Get));
            }

            if (hasNext)
            {
                links.Add(new LinkDto(createResourceUri(
                                          ids,
                                          resourceParameters,
                                          ResourceUriType.NextPage),
                                      "nextPage",
                                      HttpMethods.Get));
            }

            return(links);
        }