Esempio n. 1
0
        public GetPagesResponse Get(GetPagesRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                        .AsQueryable <PageProperties>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            if (!request.Data.IncludeMasterPages)
            {
                query = query.Where(b => !b.IsMasterPage);
            }

            query = query.ApplyPageTagsFilter(request.Data);

            if (request.User != null && !string.IsNullOrWhiteSpace(request.User.Name))
            {
                var principal = new ApiPrincipal(request.User);
                IEnumerable <Guid> deniedPages = accessControlService.GetPrincipalDeniedObjects <PageProperties>(principal, false);
                foreach (var deniedPageId in deniedPages)
                {
                    var id = deniedPageId;
                    query = query.Where(f => f.Id != id);
                }
            }

            var includeMetadata = request.Data.IncludeMetadata;
            var listResponse    = query
                                  .Select(page => new PageModel
            {
                Id             = page.Id,
                Version        = page.Version,
                CreatedBy      = page.CreatedByUser,
                CreatedOn      = page.CreatedOn,
                LastModifiedBy = page.ModifiedByUser,
                LastModifiedOn = page.ModifiedOn,

                PageUrl                 = page.PageUrl,
                Title                   = page.Title,
                Description             = page.Description,
                IsPublished             = page.Status == PageStatus.Published,
                PublishedOn             = page.PublishedOn,
                LayoutId                = page.Layout != null && !page.Layout.IsDeleted ? page.Layout.Id : (Guid?)null,
                MasterPageId            = page.MasterPage != null && !page.MasterPage.IsDeleted ? page.MasterPage.Id : (Guid?)null,
                CategoryId              = page.Category != null && !page.Category.IsDeleted ? page.Category.Id : (Guid?)null,
                CategoryName            = page.Category != null && !page.Category.IsDeleted ? page.Category.Name : null,
                MainImageId             = page.Image != null && !page.Image.IsDeleted ? page.Image.Id : (Guid?)null,
                MainImageUrl            = page.Image != null && !page.Image.IsDeleted ? page.Image.PublicUrl : null,
                MainImageThumbnauilUrl  = page.Image != null && !page.Image.IsDeleted ? page.Image.PublicThumbnailUrl : null,
                MainImageCaption        = page.Image != null && !page.Image.IsDeleted ? page.Image.Caption : null,
                IsArchived              = page.IsArchived,
                IsMasterPage            = page.IsMasterPage,
                LanguageId              = page.Language != null ? page.Language.Id : (Guid?)null,
                LanguageCode            = page.Language != null ? page.Language.Code : null,
                LanguageGroupIdentifier = page.LanguageGroupIdentifier,
                Metadata                = includeMetadata
                            ? new MetadataModel
                {
                    MetaDescription = page.MetaDescription,
                    MetaTitle       = page.MetaTitle,
                    MetaKeywords    = page.MetaKeywords,
                    UseNoFollow     = page.UseNoFollow,
                    UseNoIndex      = page.UseNoIndex,
                    UseCanonicalUrl = page.UseCanonicalUrl
                } : null
            }).ToDataListResponse(request);

            foreach (var model in listResponse.Items)
            {
                model.MainImageUrl           = fileUrlResolver.EnsureFullPathUrl(model.MainImageUrl);
                model.MainImageThumbnauilUrl = fileUrlResolver.EnsureFullPathUrl(model.MainImageThumbnauilUrl);
            }

            if (listResponse.Items.Count > 0 &&
                (request.Data.IncludePageOptions || request.Data.IncludeTags || request.Data.IncludeAccessRules))
            {
                LoadInnerCollections(listResponse, request.Data.IncludePageOptions, request.Data.IncludeTags, request.Data.IncludeAccessRules);
            }

            return(new GetPagesResponse
            {
                Data = listResponse
            });
        }