public async Task <IActionResult> List(AdminMenuListOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Forbid()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); // default options if (options == null) { options = new AdminMenuListOptions(); } var adminMenuList = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu; if (!string.IsNullOrWhiteSpace(options.Search)) { adminMenuList = adminMenuList.Where(dp => dp.Name.Contains(options.Search)).ToList(); } var count = adminMenuList.Count(); var startIndex = pager.GetStartIndex(); var pageSize = pager.PageSize; IEnumerable <Models.AdminMenu> results = new List <Models.AdminMenu>(); //todo: handle the case where there is a deserialization exception on some of the presets. // load at least the ones without error. Provide a way to delete the ones on error. try { results = adminMenuList .Skip(startIndex) .Take(pageSize) .ToList(); } catch (Exception ex) { Logger.LogError(ex, "Error when retrieving the list of admin menus"); _notifier.Error(H["Error when retrieving the list of admin menus"]); } // 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(count).RouteData(routeData); var model = new AdminMenuListViewModel { AdminMenu = results.Select(x => new AdminMenuEntry { AdminMenu = x }).ToList(), Options = options, Pager = pagerShape }; return(View(model)); }
public ActionResult IndexFilterPOST(AdminMenuListViewModel model) { return(RedirectToAction(nameof(List), new RouteValueDictionary { { "Options.Search", model.Options.Search } })); }