コード例 #1
0
ファイル: AdminController.cs プロジェクト: radtek/Plato
        // ------------------------

        private async Task <ICommandResultBase> InstallByCategoryAsync(string categoryName)
        {
            // Our result
            var result = new CommandResultBase();

            // Get all available features
            var features = await _shellDescriptorManager.GetFeaturesAsync();

            // Get all features in feature category
            var categoryFeatures = features?
                                   .Where(f => f.Descriptor.Category.Equals(categoryName, StringComparison.OrdinalIgnoreCase))
                                   .OrderBy(f => f.Descriptor.Id);

            var errors = new List <CommandError>();

            if (categoryFeatures != null)
            {
                foreach (var feature in categoryFeatures)
                {
                    var contexts = await _shellFeatureManager.EnableFeatureAsync(feature.Descriptor.Id);

                    foreach (var context in contexts)
                    {
                        if (context.Errors.Any())
                        {
                            foreach (var error in context.Errors)
                            {
                                errors.Add(new CommandError($"{context.Feature.ModuleId} could not be enabled. {error.Key} - {error.Value}"));
                            }
                        }
                    }
                }
            }

            return(errors.Count > 0
                ? result.Failed(errors.ToArray())
                : result.Success());
        }
コード例 #2
0
        public async Task <IActionResult> Enable(
            string id,
            string category,
            string returnUrl)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EnableFeatures))
            {
                return(Unauthorized());
            }

            var contexts = await _shellFeatureManager.EnableFeatureAsync(id);

            foreach (var context in contexts)
            {
                if (context.Errors.Any())
                {
                    foreach (var error in context.Errors)
                    {
                        _alerter.Danger(T[$"{context.Feature.ModuleId} could not be enabled. {error.Key} - {error.Value}"]);
                    }
                }
                else
                {
                    _alerter.Success(T[$"{context.Feature.ModuleId} enabled successfully!"]);
                }
            }

            if (!string.IsNullOrEmpty(returnUrl))
            {
                // Redirect to returnUrl
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                return(RedirectToAction(nameof(Index), new RouteValueDictionary()
                {
                    ["opts.category"] = category
                }));
            }
        }