Beispiel #1
0
        public async Task <IActionResult> CreatePost(QueriesCreateViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageQueries))
            {
                return(Unauthorized());
            }

            var query = _querySources.FirstOrDefault(x => x.Name == model.SourceName)?.Create();

            if (query == null)
            {
                return(NotFound());
            }

            var editor = await _displayManager.UpdateEditorAsync(query, this);

            if (ModelState.IsValid)
            {
                await _queryManager.SaveQueryAsync(query);

                _notifier.Success(H["Query created successfully"]);
                return(RedirectToAction("Index"));
            }

            // If we got this far, something failed, redisplay form
            model.Editor = editor;

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> CreatePost(AssesmentProfilesCreateViewModel model)
        {
            //if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageQueries))
            //{
            //    return Unauthorized();
            //}

            var presentationprofile = _assesmentEngineManager.GetEngines().FirstOrDefault(x => x.Name == model.SourceName)?.Create();

            presentationprofile.Id = Guid.NewGuid().ToString("N");

            var editor = await _displayManager.UpdateEditorAsync(presentationprofile, updater : this, isNew : true);

            if (ModelState.IsValid)
            {
                await _assesmentEngineManager.SaveProfileAsync(presentationprofile.Name, presentationprofile);

                _notifier.Success(H["Profile created successfully"]);
                return(RedirectToAction("Index"));
            }

            // If we got this far, something failed, redisplay form
            model.Editor = editor;

            return(View(model));
        }
        public async Task <IActionResult> CreatePost([Bind(Prefix = "User.Password")] string password)
        {
            var user = new User();

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

            var shape = await _userDisplayManager.UpdateEditorAsync(user, updater : _updateModelAccessor.ModelUpdater, isNew : true);

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            await _userService.CreateUserAsync(user, password, ModelState.AddModelError);

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            await _notifier.SuccessAsync(H["User created successfully."]);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> CreatePost()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageUsers))
            {
                return(Unauthorized());
            }

            var user = new User();

            var shape = await _userDisplayManager.UpdateEditorAsync(user, updater : this, isNew : true);

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            await _userService.CreateUserAsync(user, null, ModelState.AddModelError);

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            _notifier.Success(TH["User created successfully"]);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #5
0
        public async Task <IActionResult> Create(LayerRuleCreateViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageLayers))
            {
                return(Forbid());
            }

            var layers = await _layerService.LoadLayersAsync();

            var layer = layers.Layers.FirstOrDefault(x => String.Equals(x.Name, model.Name));

            if (layer == null)
            {
                return(NotFound());
            }

            var conditionGroup = FindConditionGroup(layer.LayerRule, model.ConditionGroupId);

            if (conditionGroup == null)
            {
                return(NotFound());
            }

            var condition = _factories.FirstOrDefault(x => x.Name == model.ConditionType)?.Create();

            if (condition == null)
            {
                return(NotFound());
            }

            var editor = await _displayManager.UpdateEditorAsync(condition, updater : _updateModelAccessor.ModelUpdater, isNew : true);

            if (ModelState.IsValid)
            {
                _conditionIdGenerator.GenerateUniqueId(condition);
                conditionGroup.Conditions.Add(condition);
                await _layerService.UpdateAsync(layers);

                await _notifier.SuccessAsync(H["Condition added successfully."]);

                return(RedirectToAction(nameof(Edit), "Admin", new { name = model.Name }));
            }

            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #6
0
        public async Task <IActionResult> IndexPost(string groupId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageGroupSettings, (object)groupId))
            {
                return(Unauthorized());
            }

            var cachedSite = await _siteService.GetSiteSettingsAsync();

            // Clone the settings as the driver will update it and as it's a globally cached object
            // it would stay this way even on validation errors.

            var site = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cachedSite, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            }), cachedSite.GetType()) as ISite;

            var viewModel = new AdminIndexViewModel
            {
                GroupId = groupId,
                Shape   = await _siteSettingsDisplayManager.UpdateEditorAsync(site, this, false, groupId)
            };

            if (ModelState.IsValid)
            {
                await _siteService.UpdateSiteSettingsAsync(site);

                _notifier.Success(H["Site settings updated successfully."]);

                return(RedirectToAction(nameof(Index), new { groupId }));
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> IndexPost(string groupId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageGroupSettings, (object)groupId))
            {
                return(Forbid());
            }

            var site = await _siteService.LoadSiteSettingsAsync();

            var viewModel = new AdminIndexViewModel
            {
                GroupId = groupId,
                Shape   = await _siteSettingsDisplayManager.UpdateEditorAsync(site, _updateModelAccessor.ModelUpdater, false, groupId)
            };

            if (ModelState.IsValid)
            {
                await _siteService.UpdateSiteSettingsAsync(site);

                _notifier.Success(H["Site settings updated successfully."]);

                return(RedirectToAction(nameof(Index), new { groupId }));
            }

            return(View(viewModel));
        }
Beispiel #8
0
        public async Task <IActionResult> IndexPost(string groupId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSettings))
            {
                return(Unauthorized());
            }

            var site = await _siteService.GetSiteSettingsAsync();

            var viewModel = new AdminIndexViewModel();

            viewModel.GroupId = groupId;
            viewModel.Shape   = await _siteSettingsDisplayManager.UpdateEditorAsync(site, this, groupId);

            if (ModelState.IsValid)
            {
                var siteSettings = await _siteService.GetSiteSettingsAsync();

                await _siteService.UpdateSiteSettingsAsync(siteSettings);

                _notifier.Success(H["Site settings updated successfully."]);

                return(RedirectToAction(nameof(Index), new { groupId }));
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> Create(CreateSourceViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var sitemap = await _sitemapManager.LoadSitemapAsync(model.SitemapId);

            if (sitemap == null)
            {
                return(NotFound());
            }

            var source = _factories.FirstOrDefault(x => x.Name == model.SitemapSourceType)?.Create();

            if (source == null)
            {
                return(NotFound());
            }

            dynamic editor = await _displayManager.UpdateEditorAsync(source, updater : _updateModelAccessor.ModelUpdater, isNew : true);

            editor.SitemapStep = source;

            if (ModelState.IsValid)
            {
                source.Id = model.SitemapSourceId;
                sitemap.SitemapSources.Add(source);

                // Clear sitemap cache when new source added.
                await _sitemapCacheProvider.ClearSitemapCacheAsync(sitemap.Path);

                await _sitemapManager.SaveSitemapAsync(sitemap.SitemapId, sitemap);

                _notifier.Success(H["Sitemap source added successfully"]);
                return(RedirectToAction("Display", "Admin", new { sitemapId = model.SitemapId }));
            }

            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #10
0
        public async Task <IActionResult> Create(AdminNodeEditViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu))
            {
                return(Forbid());
            }

            var adminMenuList = await _adminMenuService.LoadAdminMenuListAsync();

            var adminMenu = _adminMenuService.GetAdminMenuById(adminMenuList, model.AdminMenuId);

            if (adminMenu == null)
            {
                return(NotFound());
            }

            var treeNode = _factories.FirstOrDefault(x => x.Name == model.AdminNodeType)?.Create();

            if (treeNode == null)
            {
                return(NotFound());
            }

            dynamic editor = await _displayManager.UpdateEditorAsync(treeNode, updater : _updateModelAccessor.ModelUpdater, isNew : true);

            editor.TreeNode = treeNode;

            if (ModelState.IsValid)
            {
                treeNode.UniqueId = model.AdminNodeId;
                adminMenu.MenuItems.Add(treeNode);
                await _adminMenuService.SaveAsync(adminMenu);

                await _notifier.SuccessAsync(H["Admin node added successfully."]);

                return(RedirectToAction(nameof(List), new { id = model.AdminMenuId }));
            }

            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> IndexFilterPOST(AuditTrailIndexOptions options)
        {
            await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false);

            // When the user has typed something into the search input no further evaluation of the form post is required.
            if (!String.Equals(options.SearchText, options.OriginalSearchText, StringComparison.OrdinalIgnoreCase))
            {
                return(RedirectToAction(nameof(Index), new RouteValueDictionary {
                    { "q", options.SearchText }
                }));
            }

            // Evaluate the values provided in the form post and map them to the filter result and route values.
            await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false);

            // The route value must always be added after the editors have updated the models.
            options.RouteValues.TryAdd("q", options.FilterResult.ToString());

            return(RedirectToAction(nameof(Index), options.RouteValues));
        }
Beispiel #12
0
        public async Task <IActionResult> Create(EditDeploymentPlanStepViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan))
            {
                return(Forbid());
            }

            var deploymentPlan = await _session.GetAsync <DeploymentPlan>(model.DeploymentPlanId);

            if (deploymentPlan == null)
            {
                return(NotFound());
            }

            var step = _factories.FirstOrDefault(x => x.Name == model.DeploymentStepType)?.Create();

            if (step == null)
            {
                return(NotFound());
            }

            dynamic editor = await _displayManager.UpdateEditorAsync(step, updater : _updateModelAccessor.ModelUpdater, isNew : true);

            editor.DeploymentStep = step;

            if (ModelState.IsValid)
            {
                step.Id = model.DeploymentStepId;
                deploymentPlan.DeploymentSteps.Add(step);
                _session.Save(deploymentPlan);

                await _notifier.SuccessAsync(H["Deployment plan step added successfully."]);

                return(RedirectToAction("Display", "DeploymentPlan", new { id = model.DeploymentPlanId }));
            }

            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> Create(AdminNodeEditViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminTree))
            {
                return(Unauthorized());
            }

            var tree = await _adminTreeService.GetByIdAsync(model.AdminTreeId);

            if (tree == null)
            {
                return(NotFound());
            }

            var treeNode = _factories.FirstOrDefault(x => x.Name == model.AdminNodeType)?.Create();

            if (treeNode == null)
            {
                return(NotFound());
            }

            dynamic editor = await _displayManager.UpdateEditorAsync(treeNode, updater : this, isNew : true);

            editor.TreeNode = treeNode;

            if (ModelState.IsValid)
            {
                treeNode.UniqueId = model.AdminNodeId;
                tree.MenuItems.Add(treeNode);
                await _adminTreeService.SaveAsync(tree);

                _notifier.Success(H["Admin node added successfully"]);
                return(RedirectToAction("List", new { id = model.AdminTreeId }));
            }

            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #14
0
        public override async Task <IDisplayResult> UpdateAsync(ProjectionPart part, IUpdateModel updater)
        {
            //  var settings = GetDisqusPartSettings(model);
            // LayoutsProviderContext layoutsProviderContext = new LayoutsProviderContext(part);
            await updater.TryUpdateModelAsync(part, Prefix,
                                              t => t.Query,
                                              t => t.Hint,
                                              // t=> t.DisplayType,
                                              t => t.ProviderName,
                                              t => t.Parameters,
                                              t => t.ItemsPerPage,
                                              t => t.Skip,
                                              // t=>t.PagerSuffix,
                                              t => t.MaxItems
                                              // t=>t.DisplayPager
                                              );

            if (String.IsNullOrEmpty(part.Parameters))
            {
                part.Parameters = "{ }";
            }
            //todo
            //  _layoutsProviderManager.UpdateEditors(layoutsProviderContext, updater);
            var selectedlayoutproviderengine = _layoutsProviderManager.GetProvider(part.ProviderName);
            var layoutProfile = selectedlayoutproviderengine.Create();


            //update editor UI
            var editor = await _displayManager.UpdateEditorAsync(layoutProfile, updater : updater, isNew : true);


            //save state
            part.VisualMetadata = JsonConvert.SerializeObject(layoutProfile, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All,
                // $type no longer needs to be first
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            if (updater.ModelState.IsValid == false)
            {
                // If we got this far, something failed, redisplay form
                //  model.Editor = editor;
            }


            return(Edit(part));
        }
Beispiel #15
0
        public async ValueTask <IActionResult> IndexPost(string groupId)
        {
            var site = await _siteService.LoadSiteSettingsAsync();

            var viewModel = new AdminIndexViewModel
            {
                GroupId = groupId,
                Shape   = await _siteSettingsDisplayManager.UpdateEditorAsync(site, _updateModelAccessor.ModelUpdater, false, groupId)
            };

            if (ModelState.IsValid)
            {
                await _siteService.UpdateSiteSettingsAsync(site);

                _notifier.Success(H["Site settings updated successfully."]);

                return(RedirectToAction(nameof(Index), new { groupId }));
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> IndexPost()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageServerSettings))
            {
                return(Forbid());
            }

            var settings = await _serverService.GetSettingsAsync();

            var shape = await _serverSettingsDisplayManager.UpdateEditorAsync(settings, updater : _updateModelAccessor.ModelUpdater, isNew : false);

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            foreach (var result in await _serverService.ValidateSettingsAsync(settings))
            {
                if (result != ValidationResult.Success)
                {
                    var key = result.MemberNames.FirstOrDefault() ?? string.Empty;
                    ModelState.AddModelError(key, result.ErrorMessage);
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(shape));
            }

            await _serverService.UpdateSettingsAsync(settings);

            _notifier.Success(H["OpenID server configuration successfully updated."]);

            await _shellHost.ReloadShellContextAsync(_shellSettings);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> IndexPost(string groupId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageGroupSettings, (object)groupId))
            {
                return(Forbid());
            }

            var site = await _siteService.LoadSiteSettingsAsync();

            var viewModel = new AdminIndexViewModel
            {
                GroupId = groupId,
                Shape   = await _siteSettingsDisplayManager.UpdateEditorAsync(site, _updateModelAccessor.ModelUpdater, false, groupId)
            };

            if (ModelState.IsValid)
            {
                await _siteService.UpdateSiteSettingsAsync(site);

                string culture = null;
                if (site.Properties.TryGetValue("LocalizationSettings", out var settings))
                {
                    culture = settings.Value <string>("DefaultCulture");
                }

                // We create a transient scope with the newly selected culture to create a notification that will use it instead of the previous culture
                using (culture != null ? CultureScope.Create(culture) : null)
                {
                    _notifier.Success(H["Site settings updated successfully."]);
                }

                return(RedirectToAction(nameof(Index), new { groupId }));
            }

            return(View(viewModel));
        }
Beispiel #18
0
        public async Task <ActionResult> ListFilterPOST(ListContentsViewModel model)
        {
            await _contentOptionsDisplayManager.UpdateEditorAsync(model.Options, _updateModelAccessor.ModelUpdater, false);

            return(RedirectToAction("List", model.Options.RouteValues));
        }