public async Task <IActionResult> List(ContentOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager = new Pager(pagerParameters, siteSettings.PageSize);

            var sitemaps = (await _sitemapManager.GetSitemapsAsync())
                           .OfType <SitemapIndex>();

            if (!string.IsNullOrWhiteSpace(options.Search))
            {
                sitemaps = sitemaps.Where(x => x.Name.Contains(options.Search, StringComparison.OrdinalIgnoreCase));
            }

            var count = sitemaps.Count();

            var results = sitemaps
                          .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(count).RouteData(routeData);

            var model = new ListSitemapIndexViewModel
            {
                SitemapIndexes = results.Select(sm => new SitemapIndexListEntry {
                    SitemapId = sm.SitemapId, Name = sm.Name, Enabled = sm.Enabled
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            model.Options.ContentsBulkAction = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove)
                }
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> List(SitemapIndexListOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager = new Pager(pagerParameters, siteSettings.PageSize);

            // default options
            if (options == null)
            {
                options = new SitemapIndexListOptions();
            }

            var sitemaps = (await _sitemapManager.ListSitemapsAsync())
                           .OfType <SitemapIndex>();

            if (!string.IsNullOrWhiteSpace(options.Search))
            {
                sitemaps = sitemaps.Where(smp => smp.Name.Contains(options.Search));
            }

            var count = sitemaps.Count();

            var results = sitemaps
                          .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(count).RouteData(routeData);

            var model = new ListSitemapIndexViewModel
            {
                SitemapIndexes = results.Select(sm => new SitemapIndexListEntry {
                    SitemapId = sm.SitemapId, Name = sm.Name, Enabled = sm.Enabled
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            return(View(model));
        }
 public ActionResult ListFilterPOST(ListSitemapIndexViewModel model)
 {
     return(RedirectToAction(nameof(List), new RouteValueDictionary {
         { "Options.Search", model.Options.Search }
     }));
 }