public IActionResult Index(PageQueryModel queryModel) { if (!String.IsNullOrEmpty(queryModel.SearchString)) { queryModel.PageNumber = FIRST_PAGE_NUMBER; } queryModel.CategoryId = (queryModel.CategoryId == Guid.Empty || queryModel.CategoryId == null) ? null : queryModel.CategoryId; queryModel.SearchString = String.IsNullOrEmpty(queryModel.SearchString) ? String.Empty : queryModel.SearchString; queryModel.ColumnName = String.IsNullOrEmpty(queryModel.ColumnName) ? DEFAULT_SEARCH_COLUMN_NAME : queryModel.ColumnName; queryModel.SortColumn = String.IsNullOrEmpty(queryModel.SortColumn) ? DEFAULT_SORT_COLUMN_NAME : queryModel.SortColumn; try { int numberOfThePage = queryModel.PageNumber ?? FIRST_PAGE_NUMBER; int defaultPageSize = queryModel.PageSize ?? DEFAULT_PAGE_SIZE; int count, maxPrice; var pageModel = new PageModel() { ColumnName = queryModel.ColumnName, SearchString = queryModel.SearchString, SortColumn = queryModel.SortColumn, CountryId = CountryId, PageSize = defaultPageSize, PageIndex = numberOfThePage, CurrentUser = CurrentUserId }; var filterModel = new FilterModel() { CategoryId = queryModel.CategoryId, CityIds = queryModel.CityIds, MinimumPrice = queryModel.MinPriceValue, MaximumPrice = queryModel.MaxPriceValue }; List <AdGridViewModel> items = _adService.GetPageForAdGridByFilter(pageModel, filterModel, out count, out maxPrice); ViewData["MinimumPrice"] = queryModel.MinPriceValue; ViewData["MaximumPrice"] = queryModel.MaxPriceValue == 0 ? maxPrice : queryModel.MaxPriceValue; ViewData["CityIds"] = queryModel.CityIds; ViewData["CategoryId"] = queryModel.CategoryId; ViewData["CurrentFilter"] = queryModel.SearchString; ViewData["CurrentColumn"] = queryModel.ColumnName; ViewData["SortColumn"] = queryModel.SortColumn; ViewData["PageSize"] = queryModel.PageSize; return(View(PaginatedList <AdGridViewModel> .CreatePageAsync(items, count, numberOfThePage, defaultPageSize, maxPrice))); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(NotFound(ex.Message).WithError(ex.Message)); } }
public IActionResult MyAds(string columnName, string searchString, string sortColumn, int?pageNumber) { if (!String.IsNullOrEmpty(searchString)) { pageNumber = FIRST_PAGE_NUMBER; } searchString = String.IsNullOrEmpty(searchString) ? String.Empty : searchString; columnName = String.IsNullOrEmpty(columnName) ? DEFAULT_SEARCH_COLUMN_NAME : columnName; sortColumn = String.IsNullOrEmpty(sortColumn) ? DEFAULT_SORT_COLUMN_NAME : sortColumn; ViewData["CurrentFilter"] = searchString; ViewData["CurrentColumn"] = columnName; ViewData["SortColumn"] = sortColumn; try { int numberOfThePage = pageNumber ?? FIRST_PAGE_NUMBER; int count; var pageModel = new PageModel() { ColumnName = columnName, SearchString = searchString, SortColumn = sortColumn, CountryId = CountryId, PageSize = PAGE_SIZE, PageIndex = numberOfThePage, CurrentUser = CurrentUserId }; var items = _adService.GetPageForMyAdsGrid(pageModel, CurrentUserId, out count); return(View(PaginatedList <AdGridViewModel> .CreatePageAsync(items, count, numberOfThePage, PAGE_SIZE))); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(NotFound(ex.Message).WithError(ex.Message)); } }