コード例 #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));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(string sitemapId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var sitemap = (await _sitemapManager.GetSitemapAsync(sitemapId)) as SitemapIndex;

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

            var sitemaps = await _sitemapManager.GetSitemapsAsync();

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

            var containableSitemaps = sitemaps
                                      .Where(s => s.GetType() != typeof(SitemapIndex))
                                      .Select(s => new ContainableSitemapEntryViewModel
            {
                SitemapId = s.SitemapId,
                Name      = s.Name,
                IsChecked = indexSource.ContainedSitemapIds.Any(id => id == s.SitemapId)
            })
                                      .OrderBy(s => s.Name)
                                      .ToArray();

            var model = new EditSitemapIndexViewModel
            {
                SitemapId           = sitemap.SitemapId,
                Name                = sitemap.Name,
                Enabled             = sitemap.Enabled,
                Path                = sitemap.Path,
                SitemapIndexSource  = indexSource,
                ContainableSitemaps = containableSitemaps
            };

            return(View(model));
        }