public async Task <ActionResult> Index(int p = 1, int pageSize = 20, string orderBy = nameof(LocationDto.Name) + " asc", string search = "") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var dataTask = _locationService.SearchAsync(cts.Token, null, LocationType.Country.ToString() + "&" + search, l => !string.IsNullOrEmpty(l.Album) && !string.IsNullOrEmpty(l.UrlSlug), orderBy, p, pageSize); await TaskHelper.WhenAllOrException(cts, dataTask); var data = dataTask.Result; var total = data.TotalCount; var response = new WebApiPagedResponseDto <LocationDto> { Page = p, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderBy = orderBy, Search = search }; ViewBag.Search = search; ViewBag.Page = p; ViewBag.PageSize = pageSize; ViewBag.OrderBy = orderBy; return(View(response)); } catch { return(HandleReadException()); } }
public async Task <ActionResult> Index(int page = 1, int pageSize = 20, string orderColumn = nameof(LocationDto.Name), string orderType = "asc", string search = "") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var dataTask = _locationService.SearchAsync(cts.Token, search, l => !string.IsNullOrEmpty(l.Album) && !string.IsNullOrEmpty(l.UrlSlug), LamdaHelper.GetOrderBy <LocationDto>(orderColumn, orderType), page - 1, pageSize); var totalTask = _locationService.GetSearchCountAsync(cts.Token, search, l => !string.IsNullOrEmpty(l.Album) && !string.IsNullOrEmpty(l.UrlSlug)); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var response = new WebApiPagedResponseDto <LocationDto> { Page = page, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderColumn = orderColumn, OrderType = orderType, Search = search }; ViewBag.Search = search; ViewBag.Page = page; ViewBag.PageSize = pageSize; ViewBag.OrderColumn = orderColumn; ViewBag.OrderType = orderType; return(View(response)); } catch { return(HandleReadException()); } }