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.UpdateSitemapAsync(sitemap); return(RedirectToAction(nameof(List))); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task UpdateSitemapAsync(SitemapUpdateContext context) { var sitemaps = (await _sitemapManager.LoadSitemapsAsync()).Where(s => s.GetType() == typeof(Sitemap)); if (!sitemaps.Any()) { return; } foreach (var sitemap in sitemaps) { // Do not break out of this loop, as it must check each sitemap. foreach (var source in sitemap.SitemapSources .Select(s => s as CustomPathSitemapSource)) { if (source == null) { continue; } sitemap.Identifier = IdGenerator.GenerateId(); } } await _sitemapManager.UpdateSitemapAsync(); }
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.UpdateSitemapAsync(sitemap); _notifier.Success(H["Sitemap index created successfully"]); return(RedirectToAction(nameof(List))); } // If we got this far, something failed, redisplay form return(View(model)); }
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); await _sitemapManager.UpdateSitemapAsync(sitemap); await _notifier.SuccessAsync(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)); }
public async Task UpdateSitemapAsync(SitemapUpdateContext context) { var contentItem = context.UpdateObject as ContentItem; var allSitemaps = await _sitemapManager.LoadSitemapsAsync(); var sitemapIndex = allSitemaps .FirstOrDefault(s => s.GetType() == typeof(SitemapIndex)); if (contentItem == null || sitemapIndex == null) { return; } var sitemaps = allSitemaps.OfType <Sitemap>(); if (!sitemaps.Any()) { return; } var contentTypeName = contentItem.ContentType; foreach (var sitemap in sitemaps) { foreach (var source in sitemap.SitemapSources.Select(x => x as ContentTypesSitemapSource)) { if (source == null) { continue; } if (source.IndexAll) { sitemap.Identifier = IdGenerator.GenerateId(); break; } else if (source.LimitItems && String.Equals(source.LimitedContentType.ContentTypeName, contentTypeName)) { sitemap.Identifier = IdGenerator.GenerateId(); break; } else if (source.ContentTypes.Any(ct => String.Equals(ct.ContentTypeName, contentTypeName))) { sitemap.Identifier = IdGenerator.GenerateId(); break; } } } await _sitemapManager.UpdateSitemapAsync(); }
public async Task UpdateSitemapAsync(SitemapUpdateContext context) { var contentItem = context.UpdateObject as ContentItem; if (contentItem == null) { return; } var sitemaps = (await _sitemapManager.LoadSitemapsAsync()) .Where(s => s.GetType() == typeof(Sitemap)); if (!sitemaps.Any()) { return; } var contentTypeName = contentItem.ContentType; foreach (var sitemap in sitemaps) { // Do not break out of this loop, as it must check each sitemap. foreach (var source in sitemap.SitemapSources .Select(s => s as ContentTypesSitemapSource)) { if (source == null) { continue; } if (source.IndexAll) { sitemap.Identifier = IdGenerator.GenerateId(); break; } else if (source.LimitItems && String.Equals(source.LimitedContentType.ContentTypeName, contentTypeName)) { sitemap.Identifier = IdGenerator.GenerateId(); break; } else if (source.ContentTypes.Any(ct => String.Equals(ct.ContentTypeName, contentTypeName))) { sitemap.Identifier = IdGenerator.GenerateId(); break; } } } await _sitemapManager.UpdateSitemapAsync(); }