public async Task <IActionResult> GetAuthors( //for filtering [FromQuery] AuthorsResourceParameters authorsResourceParameters) { if (!_propertyMappingService.ValidMappingExistsFor <AuthorDto, Author>(authorsResourceParameters.OrderBy)) { return(BadRequest()); } if (!_propertyCheckerService.TypeHasProperties <AuthorDto>(authorsResourceParameters.Fields)) { return(BadRequest()); } var authorsFromRepo = await _courseLibraryRepository.GetAuthorsAsync(authorsResourceParameters); var previousPagedLink = authorsFromRepo.HasPrevious ? CreateAuthorsResourceUri(authorsResourceParameters, ResourceUriType.PreviousPage) : null; var nextPagedLink = authorsFromRepo.HasNext ? CreateAuthorsResourceUri(authorsResourceParameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = authorsFromRepo.TotalCount, pageSize = authorsFromRepo.PageSize, currentPage = authorsFromRepo.CurrentPage, totalPages = authorsFromRepo.TotalPages, previousPageLink = previousPagedLink, nextPageLink = nextPagedLink }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); return(Ok(_mapper.Map <IEnumerable <AuthorDto> >(authorsFromRepo).ShapeData(authorsResourceParameters.Fields))); }
public async Task <ActionResult <IEnumerable <AuthorDto> > > GetAuthors( //for filtering [FromQuery] AuthorsResourceParameters authorsResourceParameters) { var authorsFromRepo = await _courseLibraryRepository.GetAuthorsAsync(authorsResourceParameters); return(Ok(_mapper.Map <IEnumerable <AuthorDto> >(authorsFromRepo))); }
public async Task <ActionResult <IEnumerable <AuthorDto> > > GetAuthorCollection( [FromRoute] [ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids) { if (ids == null) { return(BadRequest()); } var authorEntities = await mRepository.GetAuthorsAsync(ids); if (ids.Count() != authorEntities.Count()) { return(NotFound()); } var authorDtos = mMapper.Map <IEnumerable <AuthorDto> >(authorEntities); return(Ok(authorDtos)); }
public async Task <IActionResult> GetAuthorCollectionAsync([FromRoute][ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids) { if (ids == null) { return(BadRequest()); } var authorEntities = await _courseLibraryRepository.GetAuthorsAsync(ids); //check if all authors are found if (ids.Count() != authorEntities.Count()) { return(NotFound()); } var authorsToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntities); return(Ok(authorsToReturn)); }