public ActionResult ExecuteAction(RecycleBinViewModel viewModel, PagerParameters pagerParameters) { if (viewModel.RecycleBinCommand == null) { ModelState.AddModelError("RecycleBinCommand", T("Please select an action to execute.").Text); } if (viewModel.SelectedContentItems == null || !viewModel.SelectedContentItems.Any()) { ModelState.AddModelError("SelectedContentItems", T("Please select one or more content items.").Text); } if (!ModelState.IsValid) { SetupViewModel(viewModel, pagerParameters); return View("Index", viewModel); } if (ModelState.IsValid) { var selectedContentItemIds = viewModel.SelectedContentItems.Where(x => x.Selected).Select(x => x.Id).ToArray(); switch (viewModel.RecycleBinCommand) { case RecycleBinCommand.Restore: RestoreContentItems(selectedContentItemIds); break; case RecycleBinCommand.Destroy: DeleteContentItems(selectedContentItemIds); break; } } return RedirectToAction("Index"); }
private RecycleBinViewModel SetupViewModel(RecycleBinViewModel viewModel, PagerParameters pagerParameters) { var pager = new Pager(_services.WorkContext.CurrentSite, pagerParameters); var removedContentItems = _recycleBin.List(pager.Page, pager.PageSize); var pagershape = _services.New.Pager(pager).TotalItemCount(removedContentItems.TotalItemCount); viewModel.ContentItems = removedContentItems; viewModel.Pager = pagershape; return viewModel; }