public async Task <ActionResult> IndexBulkActionPOST(DeploymentPlanIndexOptions options, IEnumerable <int> itemIds)
        {
            if (itemIds?.Count() > 0)
            {
                var checkedItems = await _session.Query <DeploymentPlan, DeploymentPlanIndex>().Where(x => x.DocumentId.IsIn(itemIds)).ListAsync();

                switch (options.BulkAction)
                {
                case DeploymentPlansBulkAction.None:
                    break;

                case DeploymentPlansBulkAction.Delete:
                    foreach (var item in checkedItems)
                    {
                        _session.Delete(item);

                        _notifier.Success(H["Deployment plan {0} successfully deleted.", item.Name]);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
0
        public async Task <IActionResult> Index(DeploymentPlanIndexOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan))
            {
                return(Forbid());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.Export))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

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

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

            var deploymentPlans = _session.Query <DeploymentPlan, DeploymentPlanIndex>();

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

            var count = await deploymentPlans.CountAsync();

            var results = await deploymentPlans
                          .Skip(pager.GetStartIndex())
                          .Take(pager.PageSize)
                          .ListAsync();

            // 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 DeploymentPlanIndexViewModel
            {
                DeploymentPlans = results.Select(x => new DeploymentPlanEntry {
                    DeploymentPlan = x
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            return(View(model));
        }