public SitemapSource Create() { return(new TSitemapSource() { Id = _sitemapIdGenerator.GenerateUniqueId() }); }
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 <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)); }