/// <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);
        }
        public GetSitemapTreeResponse Get(GetSitemapTreeRequest request)
        {
            var pagesToFuture        = SitemapHelper.GetPagesToFuture(cmsConfiguration.EnableMultilanguage, repository);
            var translationsToFuture = cmsConfiguration.EnableMultilanguage && request.Data.LanguageId.HasValue
                                           ? repository.AsQueryable <Module.Pages.Models.SitemapNodeTranslation>()
                                       .Where(t => t.Node.Sitemap.Id == request.SitemapId && t.Language.Id == request.Data.LanguageId.Value && !t.IsDeleted && !t.Node.IsDeleted)
                                       .Select(t => new SitemapTreeNodeTranslationModel
            {
                Id             = t.Id,
                Version        = t.Version,
                CreatedBy      = t.CreatedByUser,
                CreatedOn      = t.CreatedOn,
                LastModifiedBy = t.ModifiedByUser,
                LastModifiedOn = t.ModifiedOn,

                NodeId     = t.Node.Id,
                LanguageId = t.Language.Id,
                Title      = t.Title,
                Url        = t.Url,
                UsePageTitleAsNodeTitle = t.UsePageTitleAsNodeTitle,
                Macro = t.Macro
            })
                                       .ToFuture()
                                           : null;

            var allNodes = repository
                           .AsQueryable <Module.Pages.Models.SitemapNode>()
                           .Where(node => node.Sitemap.Id == request.SitemapId && !node.IsDeleted)
                           .OrderBy(node => node.DisplayOrder)
                           .Select(node => new SitemapTreeNodeModel
            {
                Id             = node.Id,
                Version        = node.Version,
                CreatedBy      = node.CreatedByUser,
                CreatedOn      = node.CreatedOn,
                LastModifiedBy = node.ModifiedByUser,
                LastModifiedOn = node.ModifiedOn,

                ParentId                = node.ParentNode != null && !node.ParentNode.IsDeleted ? node.ParentNode.Id : (Guid?)null,
                Title                   = node.Page != null && node.UsePageTitleAsNodeTitle ? node.Page.Title : node.Title,
                Url                     = node.Page != null ? node.Page.PageUrl : node.Url,
                PageId                  = node.Page != null ? node.Page.Id : (Guid?)null,
                PageIsPublished         = node.Page != null && !node.Page.IsDeleted && node.Page.Status == PageStatus.Published,
                UsePageTitleAsNodeTitle = node.UsePageTitleAsNodeTitle,
                DisplayOrder            = node.DisplayOrder,
                Macro                   = node.Macro
            })
                           .ToFuture()
                           .ToList();

            var nodes = GetChildren(allNodes, request.Data.NodeId);

            if (pagesToFuture != null && translationsToFuture != null)
            {
                Translate(nodes, request.Data.LanguageId, translationsToFuture.ToList(), pagesToFuture.ToList());
            }

            return(new GetSitemapTreeResponse {
                Data = nodes
            });
        }
        /// <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);
        }