Esempio n. 1
0
 public ActionResult IndexFilterPOST(WorkflowTypeIndexViewModel model)
 {
     return(RedirectToAction("Index", new RouteValueDictionary {
         { "Options.Filter", model.Options.Filter },
         { "Options.Order", model.Options.Order },
         { "Options.Search", model.Options.Search }
     }));
 }
        public async Task <IActionResult> BulkEdit(WorkflowTypeBulkAction bulkAction, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Unauthorized());
            }

            var viewModel = new WorkflowTypeIndexViewModel {
                WorkflowTypes = new List <WorkflowTypeEntry>(), Options = new WorkflowTypeIndexOptions()
            };

            if (!(await TryUpdateModelAsync(viewModel)))
            {
                return(View(viewModel));
            }

            var checkedEntries = viewModel.WorkflowTypes.Where(t => t.IsChecked);

            switch (bulkAction)
            {
            case WorkflowTypeBulkAction.None:
                break;

            case WorkflowTypeBulkAction.Delete:
                foreach (var entry in checkedEntries)
                {
                    var workflowType = await _workflowTypeStore.GetAsync(entry.Id);

                    if (workflowType != null)
                    {
                        await _workflowTypeStore.DeleteAsync(workflowType);

                        _notifier.Success(H["Workflow {0} has been deleted.", workflowType.Name]);
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(RedirectToAction("Index", new { page = pagerParameters.Page, pageSize = pagerParameters.PageSize }));
        }
        public async Task <IActionResult> Index(WorkflowTypeIndexOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Unauthorized());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

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

            if (options == null)
            {
                options = new WorkflowTypeIndexOptions();
            }

            var query = _session.Query <WorkflowType, WorkflowTypeIndex>();

            switch (options.Filter)
            {
            case WorkflowTypeFilter.All:
            default:
                break;
            }

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

            switch (options.Order)
            {
            case WorkflowTypeOrder.Name:
                query = query.OrderBy(u => u.Name);
                break;
            }

            var count = await query.CountAsync();

            var workflowTypes = await query
                                .Skip(pager.GetStartIndex())
                                .Take(pager.PageSize)
                                .ListAsync();

            var workflowTypeIds = workflowTypes.Select(x => x.WorkflowTypeId).ToList();
            var workflowGroups  = (await _session.QueryIndex <WorkflowIndex>(x => x.WorkflowTypeId.IsIn(workflowTypeIds)).ListAsync()).GroupBy(x => x.WorkflowTypeId).ToDictionary(x => x.Key);

            // Maintain previous route data when generating page links.
            var routeData = new RouteData();

            routeData.Values.Add("Options.Filter", options.Filter);
            routeData.Values.Add("Options.Search", options.Search);
            routeData.Values.Add("Options.Order", options.Order);

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count).RouteData(routeData);
            var model      = new WorkflowTypeIndexViewModel
            {
                WorkflowTypes = workflowTypes
                                .Select(x => new WorkflowTypeEntry
                {
                    WorkflowType  = x,
                    Id            = x.Id,
                    WorkflowCount = workflowGroups.ContainsKey(x.WorkflowTypeId) ? workflowGroups[x.WorkflowTypeId].Count() : 0,
                    Name          = x.Name
                })
                                .ToList(),
                Options = options,
                Pager   = pagerShape
            };

            return(View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> Index(WorkflowTypeIndexOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

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

            if (options == null)
            {
                options = new WorkflowTypeIndexOptions();
            }

            var query = _session.Query <WorkflowType, WorkflowTypeIndex>();



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

            switch (options.Filter)
            {
            case WorkflowTypeFilter.Disabled:
                query = query.Where(w => w.IsEnabled == false);
                break;

            case WorkflowTypeFilter.Enabled:
                query = query.Where(w => w.IsEnabled == true);
                break;

            case WorkflowTypeFilter.All:
            default:
                break;
            }


            switch (options.Order)
            {
            case WorkflowTypeOrder.Name:
                query = query.OrderBy(u => u.Name);
                break;

            // case WorkflowTypeOrder.Creation:
            //     query = query.OrderBy(u => u.DateCreated);
            //     break;
            case WorkflowTypeOrder.State:
                query = query.OrderBy(u => u.IsEnabled);
                break;
            }

            var count = await query.CountAsync();

            var workflowTypes = await query
                                .Skip(pager.GetStartIndex())
                                .Take(pager.PageSize)
                                .ListAsync();

            var workflowTypeIds = workflowTypes.Select(x => x.WorkflowTypeId).ToList();
            var workflowGroups  = (await _session.QueryIndex <WorkflowIndex>(x => x.WorkflowTypeId.IsIn(workflowTypeIds))
                                   .ListAsync())
                                  .GroupBy(x => x.WorkflowTypeId)
                                  .ToDictionary(x => x.Key);

            // Maintain previous route data when generating page links.
            var routeData = new RouteData();

            routeData.Values.Add("Options.Filter", options.Filter);
            routeData.Values.Add("Options.Search", options.Search);
            routeData.Values.Add("Options.Order", options.Order);

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count).RouteData(routeData);
            var model      = new WorkflowTypeIndexViewModel
            {
                WorkflowTypes = workflowTypes
                                .Select(x => new WorkflowTypeEntry
                {
                    WorkflowType  = x,
                    Id            = x.Id,
                    WorkflowCount = workflowGroups.ContainsKey(x.WorkflowTypeId) ? workflowGroups[x.WorkflowTypeId].Count() : 0,
                    Name          = x.Name,
                    Description   = x.Description
                })
                                .ToList(),
                Options = options,
                Pager   = pagerShape
            };


            // We populate the SelectLists
            model.Options.WorkflowTypeStates = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["All states"], Value = nameof(WorkflowTypeFilter.All)
                },
                new SelectListItem()
                {
                    Text = S["Enabled"], Value = nameof(WorkflowTypeFilter.Enabled)
                },
                new SelectListItem()
                {
                    Text = S["Disabled"], Value = nameof(WorkflowTypeFilter.Disabled)
                }
            };

            model.Options.WorkflowTypeSorts = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["Name"], Value = nameof(WorkflowTypeOrder.Name)
                },
                new SelectListItem()
                {
                    Text = S["State"], Value = nameof(WorkflowTypeOrder.State)
                }
            };

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

            return(View(model));
        }