Esempio n. 1
0
        public async Task <List <CustomerViewModel> > GetAllAsync()
        {
            var customers = await _repo.GetAllAsync();

            var viewCustomers = _mapper.Map <List <CustomerViewModel> >(customers);

            return(viewCustomers);
        }
        public async Task <ActionResult <IEnumerable <Customer> > > GetAllCustomers(
            [FromQuery] CustomerQueryParameters parameters)
        {
            var customers = await _repository.GetAllAsync(parameters);

            var metadata = new
            {
                ((PaginatedList <Customer>)customers).ItemCount,
                parameters.PageSize,
                ((PaginatedList <Customer>)customers).PageIndex,
                ((PaginatedList <Customer>)customers).TotalPages,
                ((PaginatedList <Customer>)customers).HasNextPage,
                ((PaginatedList <Customer>)customers).HasPreviousPage
            };


            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            return(Ok(_mapper.Map <IEnumerable <CustomerReadDto> >(customers)));
        }