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

            if (!_propertyMappingService.ValidMappingExistsFor <SongbookDto, Songbook>(parameters.OrderBy))
            {
                return(BadRequest());
            }

            var songbooks = _repository.GetSongbookByCriteria(_mapper.Map <SongbookSearchCriteria>(parameters));

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

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

            var songbookResults  = _mapper.Map <IEnumerable <SongbookResult> >(songbooks);
            var collectionResult = new SongbookCollectionResult()
            {
                Results = songbookResults, Links = CreateLinksForSongbooks(parameters, songbooks.HasNext, songbooks.HasPrevious)
            };

            return(Ok(collectionResult));
        }
Exemplo n.º 2
0
        public ActionResult <IEnumerable <SongbookResult> > GetSongbookCollection([ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids)
        {
            if (ids == null)
            {
                return(BadRequest());
            }

            _logger.LogDebug("SongbookCollectionController.Get called for ids {@ids}.", ids);
            var songbooks = _repository.GetSongbookByCriteria(new SongbookSearchCriteria()
            {
                Ids = ids.ToList(), PageNumber = 1, PageSize = ids.Count()
            });

            if (ids.Count() != songbooks.Count())
            {
                return(NotFound());
            }

            var songbooksToReturn = _mapper.Map <IEnumerable <SongbookResult> >(songbooks);

            return(Ok(songbooksToReturn.Select(CreateLinksForSongbook)));
        }