public async Task <IActionResult> Index([FromQuery] string sortOrder, [FromQuery] LaptopParams queryParams, [FromQuery] int?pageIndex) { var sortOrderEnumValue = sortOrder switch { "rating_desc" => SortOrder.SortByRatingDescending, "price_asc" => SortOrder.SortByPriceAscending, "price_desc" => SortOrder.SortByPriceDescending, _ => SortOrder.SortByRatingDescending, }; try { var data = await laptopService.Index(sortOrderEnumValue, queryParams, pageIndex ?? 1); var metadata = new { data.Count, PageSize = 14, data.PageIndex, data.TotalPages, data.HasNextPage, data.HasPreviousPage }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(data)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }