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

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

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

            if (ModelState.IsValid)
            {
                var sitemap = new Sitemap
                {
                    SitemapId = _sitemapIdGenerator.GenerateUniqueId(),
                    Name      = model.Name,
                    Path      = model.Path,
                    Enabled   = model.Enabled
                };

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

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CreateSitemapIndexViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var sitemap = new SitemapIndex
            {
                SitemapId = _sitemapIdGenerator.GenerateUniqueId()
            };

            var indexSource = new SitemapIndexSource
            {
                Id = _sitemapIdGenerator.GenerateUniqueId()
            };

            sitemap.SitemapSources.Add(indexSource);

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

            // 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);

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

                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
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));
        }