Exemplo n.º 1
0
        public ActionResult <IEnumerable <SongResult> > Get(SongResourceParameters parameters)
        {
            _logger.LogDebug("SongController.Get called with pageNumber {@pageNumber} and {@pageSize}", parameters.PageNumber, parameters.PageSize);

            //TODO: Enable a way to retrieve child objects without returning the whole parent
            var songbook = _repository.GetById(parameters.SongbookId);

            if (songbook == null)
            {
                return(NotFound());
            }

            var songs = PagedList <SongResult> .Create(_mapper.Map <IEnumerable <SongResult> >(songbook.Songs.Skip(parameters.PageNumber - 1).Take(parameters.PageSize)), parameters.PageNumber, parameters.PageSize);

            var paginationMetadata = new
            {
                totalCount  = songs.TotalCount,
                pageSize    = songs.PageSize,
                currentPage = songs.CurrentPage,
                totalPages  = songs.TotalPages
            };

            Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata));

            var songResults      = _mapper.Map <IEnumerable <SongResult> >(songs);
            var collectionResult = new SongCollectionResult()
            {
                Results = songResults, Links = CreateLinksForSongs(parameters, songs.HasNext, songs.HasPrevious)
            };

            return(Ok(collectionResult));
        }
Exemplo n.º 2
0
        public ActionResult <SongbookResult> Get(Guid id)
        {
            _logger.LogDebug("SongbookController.GetById called on id {@id}", id);
            var songbook = _repository.GetById(id);

            if (songbook == null)
            {
                return(NotFound());
            }

            var result = _mapper.Map <SongbookResult>(songbook);

            return(Ok(CreateLinksForSongbook(result)));
        }