public async Task <IActionResult> Index(ContentOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageQueries)) { return(Forbid()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); var queries = await _queryManager.ListQueriesAsync(); queries = queries.OrderBy(x => x.Name); if (!string.IsNullOrWhiteSpace(options.Search)) { queries = queries.Where(q => q.Name.IndexOf(options.Search, StringComparison.OrdinalIgnoreCase) >= 0); } var results = queries .Skip(pager.GetStartIndex()) .Take(pager.PageSize) .ToList(); // Maintain previous route data when generating page links var routeData = new RouteData(); routeData.Values.Add("Options.Search", options.Search); var pagerShape = (await New.Pager(pager)).TotalItemCount(queries.Count()).RouteData(routeData); var model = new QueriesIndexViewModel { Queries = new List <QueryEntry>(), Options = options, Pager = pagerShape, QuerySourceNames = _querySources.Select(x => x.Name).ToList() }; foreach (var query in results) { model.Queries.Add(new QueryEntry { Query = query, Shape = await _displayManager.BuildDisplayAsync(query, _updateModelAccessor.ModelUpdater, "SummaryAdmin") }); } model.Options.ContentsBulkAction = new List <SelectListItem>() { new SelectListItem() { Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove) } }; return(View(model)); }
public async Task <IActionResult> Index(QueryIndexOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageQueries)) { return(Unauthorized()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); // default options if (options == null) { options = new QueryIndexOptions(); } var queries = await _queryManager.ListQueriesAsync(); if (!string.IsNullOrWhiteSpace(options.Search)) { queries = queries.Where(q => q.Name.IndexOf(options.Search, StringComparison.OrdinalIgnoreCase) >= 0); } var results = queries .Skip(pager.GetStartIndex()) .Take(pager.PageSize) .ToList(); // Maintain previous route data when generating page links var routeData = new RouteData(); routeData.Values.Add("Options.Search", options.Search); var pagerShape = (await New.Pager(pager)).TotalItemCount(queries.Count()).RouteData(routeData); var model = new QueriesIndexViewModel { Queries = new List <QueryEntry>(), Options = options, Pager = pagerShape, QuerySourceNames = _querySources.Select(x => x.Name).ToList() }; foreach (var query in results) { model.Queries.Add(new QueryEntry { Query = query, Shape = await _displayManager.BuildDisplayAsync(query, this, "SummaryAdmin") }); } return(View(model)); }
public ActionResult IndexFilterPOST(QueriesIndexViewModel model) { return(RedirectToAction(nameof(Index), new RouteValueDictionary { { "Options.Search", model.Options.Search } })); }