public async Task <ActionResult <IEnumerable <CategoriaDTO> > > Get([FromQuery] CategoriasParameters categoriasParameters) { try { var categorias = await _uof.CategoriaRepository.GetCategorias(categoriasParameters); var metadata = new { categorias.TotalCount, categorias.PageSize, categorias.CurrentPage, categorias.TotalPages, categorias.HasNext, categorias.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); var categoriasDTO = _mapper.Map <List <CategoriaDTO> >(categorias); return(categoriasDTO); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Erro interno ao tentar obter categorias.")); } }
public async Task <ActionResult <IEnumerable <CategoriaDTO> > > Get([FromQuery] CategoriasParameters categoriasParameters) { try { //AsNoTracking somente em consultas, um ganho de performance var categorias = await _uof.CategoriaRepository.GetCategorias(categoriasParameters); var metadata = new { categorias.TotalCount, categorias.PageSize, categorias.CurrentPage, categorias.TotalPages, categorias.HasNext, categorias.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); var categoriaDTO = _mapper.Map <List <CategoriaDTO> >(categorias); return(categoriaDTO); } catch (Exception) { /* consulte https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.statuscodes?view=aspnetcore-5.0 */ return(StatusCode(StatusCodes.Status500InternalServerError, "Erro ao tentar obter as categorias do banco de dados")); } }
public PagedList <Categoria> GetCategorias(CategoriasParameters categoriasParameters) { //return Get() // .OrderBy(on => on.CategoriaId) // .Skip((categoriasParameters.PageNumber - 1) * categoriasParameters.PageSize) // .Take(categoriasParameters.PageSize) // .ToList(); return(PagedList <Categoria> .ToPagedList(Get().OrderBy(on => on.CategoriaId), categoriasParameters.PageNumber, categoriasParameters.PageSize)); }
public async Task <PagedList <Categoria> > GetCategorias(CategoriasParameters categoriasParameters) { //return Get() // .OrderBy(on => on.Nome) // .Skip((produtosParameters.PageNumber - 1) * produtosParameters.PageSize) // .Take(produtosParameters.PageSize) // .ToList(); return(await PagedList <Categoria> .ToPagedList(Get().OrderBy(on => on.Nome), categoriasParameters.PageNumber, categoriasParameters.PageSize)); }
public async Task <ActionResult <IEnumerable <CategoriaDTO> > > Get([FromQuery] CategoriasParameters categoriasParameters) { PagedList <Categoria> categorias = await _uof.CategoriaRepository.GetCategorias(categoriasParameters); var metadata = new { categorias.TotalCount, categorias.PageSize, categorias.CurrentPage, categorias.TotalPages, categorias.HasNext, categorias.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); List <CategoriaDTO> categoriaDTO = _mapper.Map <List <CategoriaDTO> >(categorias); return(categoriaDTO); }
public async Task <PagedList <Categoria> > GetCategorias(CategoriasParameters categoriasParameters) { return(await PagedList <Categoria> .ToPagedList(Get().OrderBy(on => on.Nome), categoriasParameters.PageNumber, categoriasParameters.PageSize)); }