public ActionResult Index(AdminIndexOptions options, PagerParameters pagerParameters) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases"))) return new HttpUnauthorizedResult(); var pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters); // default options if (options == null) options = new AdminIndexOptions(); switch (options.Filter) { case AliasFilter.All: break; default: throw new ArgumentOutOfRangeException(); } var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()); if (!String.IsNullOrWhiteSpace(options.Search)) { var invariantSearch = options.Search.ToLowerInvariant(); aliases = aliases.Where(x => x.Path.ToLowerInvariant().Contains(invariantSearch)); } aliases = aliases.ToList(); var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count()); switch (options.Order) { case AliasOrder.Path: aliases = aliases.OrderBy(x => x.Path); break; } if (pager.PageSize != 0) { aliases = aliases.Skip(pager.GetStartIndex()).Take(pager.PageSize); } var model = new AdminIndexViewModel { Options = options, Pager = pagerShape, AliasEntries = aliases.Select(x => new AliasEntry() {Alias = x, IsChecked = false}).ToList() }; return View(model); }
public ActionResult IndexUnmanaged(FormCollection input) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases"))) return new HttpUnauthorizedResult(); var viewModel = new AdminIndexViewModel { AliasEntries = new List<AliasEntry>(), Options = new AdminIndexOptions() }; UpdateModel(viewModel); var checkedItems = viewModel.AliasEntries.Where(c => c.IsChecked); switch (viewModel.Options.BulkAction) { case AliasBulkAction.None: break; case AliasBulkAction.Delete: foreach (var checkedItem in checkedItems) { _aliasService.Delete(checkedItem.Alias.Path); } break; default: throw new ArgumentOutOfRangeException(); } return RedirectToAction("IndexUnmanaged"); }