/// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <returns>
        /// Sitemap list.
        /// </returns>
        public List <SitemapViewModel> Execute()
        {
            var sitemaps        = new List <SitemapViewModel>();
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);
            IQueryable <Models.Sitemap> sitemapQuery =
                Repository.AsQueryable <Models.Sitemap>().FetchMany(map => map.AccessRules).FetchMany(map => map.Nodes).ThenFetch(node => node.Page);

            if (CmsConfiguration.EnableMultilanguage)
            {
                sitemapQuery = sitemapQuery
                               .FetchMany(map => map.Nodes)
                               .ThenFetchMany(node => node.Translations);
            }

            var allSitmaps = sitemapQuery.Distinct().ToFuture().ToList();
            var languages  = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();

            foreach (var sitemap in allSitmaps)
            {
                var model = new SitemapViewModel
                {
                    Id        = sitemap.Id,
                    Version   = sitemap.Version,
                    Title     = sitemap.Title,
                    RootNodes =
                        SitemapHelper.GetSitemapNodesInHierarchy(
                            CmsConfiguration.EnableMultilanguage,
                            sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                            sitemap.Nodes.Distinct().ToList(),
                            languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                            (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                    Languages            = languages,
                    ShowMacros           = false
                };

                if (CmsConfiguration.Security.AccessControlEnabled)
                {
                    model.UserAccessList = sitemap.AccessRules.Distinct().Select(x => new UserAccessViewModel(x)).ToList();
                    var rules = model.UserAccessList.Cast <IAccessRule>().ToList();
                    SetIsReadOnly(model, rules);
                }

                if (!model.IsReadOnly)
                {
                    sitemaps.Add(model);
                }
            }

            return(sitemaps.Count > 0 ? sitemaps.OrderBy(map => map.Title).ToList() : null);
        }
Exemple #2
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="versionId">The sitemap version identifier.</param>
        /// <returns>
        /// Sitemap view model.
        /// </returns>
        public SitemapViewModel Execute(Guid versionId)
        {
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);

            // Return current or old version.
            var sitemap = Repository.AsQueryable <Models.Sitemap>()
                          .Where(map => map.Id == versionId)
                          .FetchMany(map => map.Nodes)
                          .ThenFetch(node => node.Page)
                          .FetchMany(map => map.Nodes)
                          .ThenFetchMany(node => node.Translations)
                          .Distinct()
                          .ToFuture()
                          .ToList()
                          .FirstOrDefault() ?? SitemapService.GetArchivedSitemapVersionForPreview(versionId);

            if (sitemap != null)
            {
                var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();
                var model     = new SitemapViewModel
                {
                    Id        = sitemap.Id,
                    Version   = sitemap.Version,
                    Title     = sitemap.Title,
                    RootNodes =
                        SitemapHelper.GetSitemapNodesInHierarchy(
                            CmsConfiguration.EnableMultilanguage,
                            sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                            sitemap.Nodes.Distinct().ToList(),
                            languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                            (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                    Languages            = languages,
                    IsReadOnly           = true,
                    ShowMacros           = false
                };

                return(model);
            }

            return(null);
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="sitemapId">The sitemap identifier.</param>
        /// <returns>
        /// Sitemap view model.
        /// </returns>
        public SitemapViewModel Execute(Guid sitemapId)
        {
            if (sitemapId.HasDefaultValue())
            {
                var langs = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues().ToList() : new List <LookupKeyValue>();
                return(new SitemapViewModel()
                {
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    UserAccessList = AccessControlService.GetDefaultAccessList(SecurityService.GetCurrentPrincipal()).Select(f => new UserAccessViewModel(f)).ToList(),
                    ShowLanguages = CmsConfiguration.EnableMultilanguage && langs.Any(),
                    Languages = langs,
                    ShowMacros = CmsConfiguration.EnableMacros
                });
            }

            IEnumerable <AccessRule> userAccessFuture;

            if (CmsConfiguration.Security.AccessControlEnabled)
            {
                userAccessFuture = Repository
                                   .AsQueryable <Models.Sitemap>()
                                   .Where(x => x.Id == sitemapId && !x.IsDeleted)
                                   .SelectMany(x => x.AccessRules)
                                   .OrderBy(x => x.Identity)
                                   .ToFuture();
            }
            else
            {
                userAccessFuture = null;
            }

            var tagsFuture      = TagService.GetSitemapTagNames(sitemapId);
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);

            IQueryable <Models.Sitemap> sitemapQuery = Repository.AsQueryable <Models.Sitemap>()
                                                       .Where(map => map.Id == sitemapId)
                                                       .FetchMany(map => map.Nodes)
                                                       .ThenFetch(node => node.Page);

            if (CmsConfiguration.EnableMultilanguage)
            {
                sitemapQuery = sitemapQuery
                               .FetchMany(map => map.Nodes)
                               .ThenFetchMany(node => node.Translations);
            }

            var sitemap   = sitemapQuery.Distinct().ToFuture().ToList().First();
            var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();
            var model     = new SitemapViewModel
            {
                Id        = sitemap.Id,
                Version   = sitemap.Version,
                Title     = sitemap.Title,
                RootNodes =
                    SitemapHelper.GetSitemapNodesInHierarchy(
                        CmsConfiguration.EnableMultilanguage,
                        sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                        sitemap.Nodes.Distinct().ToList(),
                        languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                        (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                Tags = tagsFuture.ToList(),
                AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                Languages            = languages,
                ShowMacros           = CmsConfiguration.EnableMacros
            };

            if (userAccessFuture != null)
            {
                model.UserAccessList = userAccessFuture.Select(x => new UserAccessViewModel(x)).ToList();

                var rules = model.UserAccessList.Cast <IAccessRule>().ToList();

                SetIsReadOnly(model, rules);
            }

            return(model);
        }