public IActionResult GetManufacturers([FromQuery] ManufacturersParameters parameters) { try { var manufacturers = _repository.Manufacturer.GetManufacturers(parameters); var metadata = new { manufacturers.TotalCount, manufacturers.PageSize, manufacturers.CurrentPage, manufacturers.TotalPages, manufacturers.HasNext, manufacturers.HasPrevious }; Response.Headers.Add("X-Pagination:", JsonConvert.SerializeObject(metadata)); var result = Mapping.Mapper.Map <IEnumerable <ManufacturerDTO> >(manufacturers); Log.Information("Returned all manufacturers from database"); return(Ok(result)); } catch (Exception ex) { Log.Error($"Something went wrong: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public PagedList <Manufacturer> GetManufacturers(ManufacturersParameters parameters) { var manufacturers = FindAll(); ApplySort(ref manufacturers, parameters.OrderBy); return(PagedList <Manufacturer> .ToPagedList(FindAll().OrderBy(x => x.Name), parameters.PageNumber, parameters.PageSize)); }