Exemplo n.º 1
0
        public async Task <IActionResult> Edit(EditSitemapIndexViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

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

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

            var indexSource = sitemap.SitemapSources.FirstOrDefault() as SitemapIndexSource;

            model.SitemapIndexSource = indexSource;

            if (ModelState.IsValid)
            {
                await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater, sitemap.SitemapId);
            }

            // Path validation may invalidate model state.
            if (ModelState.IsValid)
            {
                sitemap.Name    = model.Name;
                sitemap.Enabled = model.Enabled;
                sitemap.Path    = model.Path;

                indexSource.ContainedSitemapIds = model.ContainableSitemaps
                                                  .Where(m => m.IsChecked)
                                                  .Select(m => m.SitemapId)
                                                  .ToArray();

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

                // Always clear sitemap index cache when updated.
                await _sitemapCacheProvider.ClearSitemapCacheAsync(sitemap.Path);

                _notifier.Success(H["Sitemap index updated successfully"]);

                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(EditSitemapViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

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

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

            if (ModelState.IsValid)
            {
                if (String.IsNullOrEmpty(model.Path))
                {
                    model.Path = _sitemapService.GetSitemapSlug(model.Name);
                }

                await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater, model.SitemapId);
            }

            if (ModelState.IsValid)
            {
                sitemap.Name    = model.Name;
                sitemap.Enabled = model.Enabled;
                sitemap.Path    = model.Path;

                await _sitemapManager.UpdateSitemapAsync(sitemap);

                await _notifier.SuccessAsync(H["Sitemap updated successfully."]);

                return(RedirectToAction(nameof(List)));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }