public async Task <IActionResult> GetAsync([FromQuery] QueryParams queryParams) { var filter = new Filter(queryParams.SearchBy, queryParams.Search); var sorting = new Sorting(queryParams.SortBy, queryParams.SortType); var paging = new Paging(queryParams.PageNumber, queryParams.PageSize); dynamic obj = new ExpandoObject(); obj.VehicleMakes = await vehicleMakeService.GetAllMakesAsync(filter, paging, sorting); obj.Pagination = paging; obj.Filter = filter; obj.Sorting = sorting; return(Ok(JsonSerializer.Serialize(obj))); }
public async Task <IActionResult> GetVehicleMakeAsync(string searchBy, string search, string sortBy, string sortType, int?page, int?pageSize) { page = page == null ? 1 : page; pageSize = pageSize == null ? 5 : pageSize; sortType = string.IsNullOrEmpty(sortType) ? "asc" : sortType; ViewBag.Sorting = sortType; ViewBag.SortBy = !string.IsNullOrEmpty(sortBy) ? sortBy : "Name"; ViewBag.Search = !string.IsNullOrEmpty(search) ? search : ""; ViewBag.SearchBy = !string.IsNullOrEmpty(searchBy) ? searchBy : "Name"; ViewBag.CurrentPage = page; ViewBag.PageSize = pageSize; var filter = new Filter() { SearchBy = searchBy, Search = search, SortBy = sortBy, SortType = sortType }; var paging = new Paging() { PageNumber = (int)page, PageSize = (int)pageSize }; var result = await vehicleMakeService.GetAllMakesAsync(filter, paging); var vehicleMakes = (IEnumerable <IVehicleMakeDTO>)result["makes"]; var pagination = (IPaging)result["paging"]; var pageCount = pagination.TotalItemsCount / pageSize; ViewBag.TotalPageCount = pagination.TotalItemsCount % pageSize == 0 ? pageCount : pageCount + 1; if (vehicleMakes.Any()) { return(View(mapper.Map <IEnumerable <VehicleMakeViewModel> >(vehicleMakes))); } else { ViewBag.Message = "There are no Vehicle Makes to show."; return(View()); } }