/// <summary>
        /// Gets the specified page properties.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>GetPagePropertiesResponse</c> with a page properties data.
        /// </returns>
        public GetPagePropertiesResponse Get(GetPagePropertiesRequest request)
        {
            var query = repository.AsQueryable<PageProperties>();

            if (request.PageId.HasValue)
            {
                query = query.Where(page => page.Id == request.PageId.Value);
            }
            else
            {
                var url = urlService.FixUrl(request.PageUrl);
                query = query.Where(page => page.PageUrlHash == url.UrlHash());
            }

            var response = query
                .Select(page => new GetPagePropertiesResponse
                    {
                        Data = new PagePropertiesModel
                            {
                                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,
                                IsArchived = page.IsArchived,
                                IsMasterPage = page.IsMasterPage,
                                LanguageGroupIdentifier = page.LanguageGroupIdentifier,
                                ForceAccessProtocol = (ForceProtocolType)(int)page.ForceAccessProtocol,
                                LanguageId = page.Language != null ? page.Language.Id : (Guid?)null,
                                MainImageId = page.Image != null && !page.Image.IsDeleted ? page.Image.Id : (Guid?)null,
                                FeaturedImageId = page.FeaturedImage != null && !page.FeaturedImage.IsDeleted ? page.FeaturedImage.Id : (Guid?)null,
                                SecondaryImageId = page.SecondaryImage != null && !page.SecondaryImage.IsDeleted ? page.SecondaryImage.Id : (Guid?)null,
                                CustomCss = page.CustomCss,
                                CustomJavaScript = page.CustomJS,
                                UseCanonicalUrl = page.UseCanonicalUrl,
                                UseNoFollow = page.UseNoFollow,
                                UseNoIndex = page.UseNoIndex
                            },
                        MetaData = request.Data.IncludeMetaData
                            ? new MetadataModel
                            {
                                MetaTitle = page.MetaTitle,
                                MetaDescription = page.MetaDescription,
                                MetaKeywords = page.MetaKeywords
                            }
                            : null,
                        Layout = request.Data.IncludeLayout && !page.Layout.IsDeleted
                            ? new LayoutModel
                            {
                                Id = page.Layout.Id,
                                Version = page.Layout.Version,
                                CreatedBy = page.Layout.CreatedByUser,
                                CreatedOn = page.Layout.CreatedOn,
                                LastModifiedBy = page.Layout.ModifiedByUser,
                                LastModifiedOn = page.Layout.ModifiedOn,

                                Name = page.Layout.Name,
                                LayoutPath = page.Layout.LayoutPath,
                                PreviewUrl = page.Layout.PreviewUrl
                            }
                            : null,
                        MainImage = page.Image != null && !page.Image.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.Image.Id,
                                Version = page.Image.Version,
                                CreatedBy = page.Image.CreatedByUser,
                                CreatedOn = page.Image.CreatedOn,
                                LastModifiedBy = page.Image.ModifiedByUser,
                                LastModifiedOn = page.Image.ModifiedOn,

                                Title = page.Image.Title,
                                Caption = page.Image.Caption,
                                Url = fileUrlResolver.EnsureFullPathUrl(page.Image.PublicUrl),
                                ThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(page.Image.PublicThumbnailUrl)
                            }
                            : null,
                        FeaturedImage = page.FeaturedImage != null && !page.FeaturedImage.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.FeaturedImage.Id,
                                Version = page.FeaturedImage.Version,
                                CreatedBy = page.FeaturedImage.CreatedByUser,
                                CreatedOn = page.FeaturedImage.CreatedOn,
                                LastModifiedBy = page.FeaturedImage.ModifiedByUser,
                                LastModifiedOn = page.FeaturedImage.ModifiedOn,

                                Title = page.FeaturedImage.Title,
                                Caption = page.FeaturedImage.Caption,
                                Url = fileUrlResolver.EnsureFullPathUrl(page.FeaturedImage.PublicUrl),
                                ThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(page.FeaturedImage.PublicThumbnailUrl)
                            }
                            : null,
                        SecondaryImage = page.SecondaryImage != null && !page.SecondaryImage.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.SecondaryImage.Id,
                                Version = page.SecondaryImage.Version,
                                CreatedBy = page.SecondaryImage.CreatedByUser,
                                CreatedOn = page.SecondaryImage.CreatedOn,
                                LastModifiedBy = page.SecondaryImage.ModifiedByUser,
                                LastModifiedOn = page.SecondaryImage.ModifiedOn,

                                Title = page.SecondaryImage.Title,
                                Caption = page.SecondaryImage.Caption,
                                Url = fileUrlResolver.EnsureFullPathUrl(page.SecondaryImage.PublicUrl),
                                ThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(page.SecondaryImage.PublicThumbnailUrl)
                            }
                            : null,
                        Language = page.Language != null && !page.Language.IsDeleted && request.Data.IncludeLanguage
                            ? new LanguageModel
                            {
                                Id = page.Language.Id,
                                Version = page.Language.Version,
                                CreatedBy = page.Language.CreatedByUser,
                                CreatedOn = page.Language.CreatedOn,
                                LastModifiedBy = page.Language.ModifiedByUser,
                                LastModifiedOn = page.Language.ModifiedOn,

                                Name = page.Language.Name,
                                Code = page.Language.Code,
                            }
                            : null,
                    })
                .FirstOne();

            if (request.Data.IncludeTags)
            {
                response.Tags = LoadTags(response.Data.Id);
            }

            if (request.Data.IncludePageContents)
            {
                response.PageContents = LoadPageContents(response.Data.Id);
            }

            if (request.Data.IncludePageOptions)
            {
                // Get layout options, page options and merge them
                response.PageOptions = optionService
                    .GetMergedMasterPagesOptionValues(response.Data.Id, response.Data.MasterPageId, response.Data.LayoutId)
                    .Select(o => new OptionValueModel
                        {
                            Key = o.OptionKey,
                            Value = o.OptionValue,
                            DefaultValue = o.OptionDefaultValue,
                            Type = (Root.OptionType)(int)o.Type,
                            UseDefaultValue = o.UseDefaultValue,
                            CustomTypeIdentifier = o.CustomOption != null ? o.CustomOption.Identifier : null
                        })
                    .ToList();
            }

            if (request.Data.IncludeAccessRules)
            {
                response.AccessRules = LoadAccessRules(response.Data.Id);
            }

            if (request.Data.IncludePageTranslations
                && response.Data.LanguageGroupIdentifier.HasValue)
            {
                response.PageTranslations = repository
                    .AsQueryable<PageProperties>()
                    .Where(p => p.LanguageGroupIdentifier == response.Data.LanguageGroupIdentifier)
                    .OrderBy(p => p.Title)
                    .Select(p => new PageTranslationModel
                        {
                            Id = p.Id,
                            Title = p.Title,
                            PageUrl = p.PageUrl,
                            LanguageId = p.Language != null ? p.Language.Id : (Guid?)null,
                            LanguageCode = p.Language != null ? p.Language.Code : null,
                        })
                    .ToList();
            }

            response.Data.Categories = categoryService.GetSelectedCategoriesIds<PageProperties, PageCategory>(response.Data.Id).ToList();

            if (request.Data.IncludeCategories)
            {
                response.Categories = LoadCategories(response.Data.Id);
            }

            return response;
        }
Beispiel #2
0
        public void Synch_Crud_Examples()
        {
            using (var api = ApiFactory.Create())
            {
                // Tags:
                var tag = api.Root.Tag.Get(new GetTagRequest());
                api.Root.Tags.Post(tag.ToPostRequest());
                api.Root.Tag.Put(tag.ToPutRequest());
                api.Root.Tag.Delete(new DeleteTagRequest());

                // Categories:
                var category = api.Root.Category.Get(new GetCategoryRequest());
                api.Root.Categories.Post(category.ToPostRequest());
                api.Root.Category.Put(category.ToPutRequest());
                api.Root.Category.Delete(new DeleteCategoryRequest());

                // Layouts:
                var getLayoutRequest = new GetLayoutRequest();
                getLayoutRequest.Data.IncludeOptions = true;
                getLayoutRequest.Data.IncludeRegions = true;
                var layout = api.Root.Layout.Get(getLayoutRequest);
                api.Root.Layouts.Post(layout.ToPostRequest());
                api.Root.Layout.Put(layout.ToPutRequest());
                api.Root.Layout.Delete(new DeleteLayoutRequest());

                // Folders:
                var folder = api.Media.Folder.Get(new GetFolderRequest());
                api.Media.Folders.Post(folder.ToPostRequest());
                api.Media.Folder.Put(folder.ToPutRequest());
                api.Media.Folder.Delete(new DeleteFolderRequest());

                // Images:
                var image = api.Media.Image.Get(new GetImageRequest());
                api.Media.Images.Post(image.ToPostRequest());
                api.Media.Image.Put(image.ToPutRequest());
                api.Media.Image.Delete(new DeleteImageRequest());

                // Files:
                var file = api.Media.File.Get(new GetFileRequest());
                api.Media.Files.Post(file.ToPostRequest());
                api.Media.File.Put(file.ToPutRequest());
                api.Media.File.Delete(new DeleteFileRequest());

                // Languages:
                var language = api.Root.Language.Get(new GetLanguageRequest());
                api.Root.Languages.Post(language.ToPostRequest());
                api.Root.Language.Put(language.ToPutRequest());
                api.Root.Language.Delete(new DeleteLanguageRequest());

                // Redirects:
                var redirect = api.Pages.Redirect.Get(new GetRedirectRequest());
                api.Pages.Redirects.Post(redirect.ToPostRequest());
                api.Pages.Redirect.Put(redirect.ToPutRequest());
                api.Pages.Redirect.Delete(new DeleteRedirectRequest());

                // Server Widget:
                var getSWRequest = new GetServerControlWidgetRequest();
                getSWRequest.Data.IncludeOptions = true;
                var serverWidget = api.Pages.Widget.ServerControl.Get(getSWRequest);
                api.Pages.Widget.ServerControl.Post(serverWidget.ToPostRequest());
                api.Pages.Widget.ServerControl.Put(serverWidget.ToPutRequest());
                api.Pages.Widget.ServerControl.Delete(new DeleteServerControlWidgetRequest());

                // Html Widgets:
                var getHWRequest = new GetHtmlContentWidgetRequest();
                getHWRequest.Data.IncludeOptions = true;
                var htmlWidget = api.Pages.Widget.HtmlContent.Get(getHWRequest);
                api.Pages.Widget.HtmlContent.Post(htmlWidget.ToPostRequest());
                api.Pages.Widget.HtmlContent.Put(htmlWidget.ToPutRequest());
                api.Pages.Widget.HtmlContent.Delete(new DeleteHtmlContentWidgetRequest());

                // Html Contents:
                var html = api.Pages.Content.Html.Get(new GetHtmlContentRequest());
                // TODO: implement post.
                api.Pages.Content.Html.Put(html.ToPutRequest());
                api.Pages.Content.Html.Delete(new DeleteHtmlContentRequest());

                // Pages:
                var getPageRequest = new GetPagePropertiesRequest();
                getPageRequest.Data.IncludeAccessRules = true;
                getPageRequest.Data.IncludePageOptions = true;
                getPageRequest.Data.IncludeMetaData = true;
                getPageRequest.Data.IncludeTags = true;
                var page = api.Pages.Page.Properties.Get(getPageRequest);
                api.Pages.Page.Properties.Post(page.ToPostRequest());
                api.Pages.Page.Properties.Put(page.ToPutRequest());
                api.Pages.Page.Properties.Delete(new DeletePagePropertiesRequest());

                // Page Contents:
                var getPCrequest = new GetPageContentRequest();
                getPCrequest.Data.IncludeOptions = true; // Only when options should be retrieved and saved
                var pageContent = api.Pages.Page.Content.Get(getPCrequest);
                api.Pages.Page.Content.Put(pageContent.ToPutRequest());
                api.Pages.Page.Content.Delete(new DeletePageContentRequest());

                // Blog Post:
                var getBlogRequest = new GetBlogPostPropertiesRequest();
                getBlogRequest.Data.IncludeHtmlContent = true;
                getBlogRequest.Data.IncludeAccessRules = true;
                getBlogRequest.Data.IncludeMetaData = true;
                getBlogRequest.Data.IncludeTags = true;
                var blog = api.Blog.BlogPost.Properties.Get(getBlogRequest);
                api.Blog.BlogPost.Properties.Post(blog.ToPostRequest());
                api.Blog.BlogPost.Properties.Put(blog.ToPutRequest());
                api.Blog.BlogPost.Properties.Delete(new DeleteBlogPostPropertiesRequest());
                var author = api.Blog.Author.Get(new GetAuthorRequest());
                api.Blog.Authors.Post(author.ToPostRequest());
                api.Blog.Author.Put(author.ToPutRequest());
                api.Blog.Author.Delete(new DeleteAuthorRequest());
                var settings = api.Blog.Settings.Get(new GetBlogPostsSettingsRequest());
                api.Blog.Settings.Put(settings.ToPutRequest());

                // Sitemap:
                var sitemap = api.Pages.SitemapNew.Get(new GetSitemapRequest());
                api.Pages.Sitemaps.Post(sitemap.ToPostRequest());
                api.Pages.SitemapNew.Put(sitemap.ToPutRequest());
                api.Pages.SitemapNew.Delete(new DeleteSitemapRequest());

                // Sitemap nodes:
                var node = api.Pages.SitemapNew.Node.Get(new GetNodeRequest());
                api.Pages.SitemapNew.Nodes.Post(node.ToPostRequest());
                api.Pages.SitemapNew.Node.Put(node.ToPutRequest());
                api.Pages.SitemapNew.Node.Delete(new DeleteNodeRequest());

                // Destroyed draft (should be called on event BetterCms.Events.PageEvents.Instance.ContentDraftDestroyed)
                var destroyDraftRequest = new DestroyContentDraftRequest();
                // destroyDraftRequest.ContentId = contentId;
                api.Pages.Content.Draft.Delete(destroyDraftRequest);
            }
        }
        public void Synch_Crud_Examples()
        {
            using (var api = ApiFactory.Create())
            {
                // Tags:
                var tag = api.Root.Tag.Get(new GetTagRequest());
                api.Root.Tags.Post(tag.ToPostRequest());
                api.Root.Tag.Put(tag.ToPutRequest());
                api.Root.Tag.Delete(new DeleteTagRequest());

                // Categories:
                var category = api.Root.Category.Get(new GetCategoryRequest());
                api.Root.Categories.Post(category.ToPostRequest());
                api.Root.Category.Put(category.ToPutRequest());
                api.Root.Category.Delete(new DeleteCategoryRequest());

                // Layouts:
                var getLayoutRequest = new GetLayoutRequest();
                getLayoutRequest.Data.IncludeOptions = true;
                getLayoutRequest.Data.IncludeRegions = true;
                var layout = api.Root.Layout.Get(getLayoutRequest);
                api.Root.Layouts.Post(layout.ToPostRequest());
                api.Root.Layout.Put(layout.ToPutRequest());
                api.Root.Layout.Delete(new DeleteLayoutRequest());

                // Folders:
                var folder = api.Media.Folder.Get(new GetFolderRequest());
                api.Media.Folders.Post(folder.ToPostRequest());
                api.Media.Folder.Put(folder.ToPutRequest());
                api.Media.Folder.Delete(new DeleteFolderRequest());

                // Images:
                var image = api.Media.Image.Get(new GetImageRequest());
                api.Media.Images.Post(image.ToPostRequest());
                api.Media.Image.Put(image.ToPutRequest());
                api.Media.Image.Delete(new DeleteImageRequest());

                // Files:
                var file = api.Media.File.Get(new GetFileRequest());
                api.Media.Files.Post(file.ToPostRequest());
                api.Media.File.Put(file.ToPutRequest());
                api.Media.File.Delete(new DeleteFileRequest());

                // Languages:
                var language = api.Root.Language.Get(new GetLanguageRequest());
                api.Root.Languages.Post(language.ToPostRequest());
                api.Root.Language.Put(language.ToPutRequest());
                api.Root.Language.Delete(new DeleteLanguageRequest());

                // Redirects:
                var redirect = api.Pages.Redirect.Get(new GetRedirectRequest());
                api.Pages.Redirects.Post(redirect.ToPostRequest());
                api.Pages.Redirect.Put(redirect.ToPutRequest());
                api.Pages.Redirect.Delete(new DeleteRedirectRequest());

                // Server Widget:
                var getSWRequest = new GetServerControlWidgetRequest();
                getSWRequest.Data.IncludeOptions = true;
                var serverWidget = api.Pages.Widget.ServerControl.Get(getSWRequest);
                api.Pages.Widget.ServerControl.Post(serverWidget.ToPostRequest());
                api.Pages.Widget.ServerControl.Put(serverWidget.ToPutRequest());
                api.Pages.Widget.ServerControl.Delete(new DeleteServerControlWidgetRequest());

                // Html Widgets:
                var getHWRequest = new GetHtmlContentWidgetRequest();
                getHWRequest.Data.IncludeOptions = true;
                var htmlWidget = api.Pages.Widget.HtmlContent.Get(getHWRequest);
                api.Pages.Widget.HtmlContent.Post(htmlWidget.ToPostRequest());
                api.Pages.Widget.HtmlContent.Put(htmlWidget.ToPutRequest());
                api.Pages.Widget.HtmlContent.Delete(new DeleteHtmlContentWidgetRequest());

                // Html Contents:
                var html = api.Pages.Content.Html.Get(new GetHtmlContentRequest());
                // TODO: implement post.
                api.Pages.Content.Html.Put(html.ToPutRequest());
                api.Pages.Content.Html.Delete(new DeleteHtmlContentRequest());

                // Pages:
                var getPageRequest = new GetPagePropertiesRequest();
                getPageRequest.Data.IncludeAccessRules = true;
                getPageRequest.Data.IncludePageOptions = true;
                getPageRequest.Data.IncludeMetaData    = true;
                getPageRequest.Data.IncludeTags        = true;
                var page = api.Pages.Page.Properties.Get(getPageRequest);
                api.Pages.Page.Properties.Post(page.ToPostRequest());
                api.Pages.Page.Properties.Put(page.ToPutRequest());
                api.Pages.Page.Properties.Delete(new DeletePagePropertiesRequest());

                // Page Contents:
                var getPCrequest = new GetPageContentRequest();
                getPCrequest.Data.IncludeOptions = true; // Only when options should be retrieved and saved
                var pageContent = api.Pages.Page.Content.Get(getPCrequest);
                api.Pages.Page.Content.Put(pageContent.ToPutRequest());
                api.Pages.Page.Content.Delete(new DeletePageContentRequest());

                // Blog Post:
                var getBlogRequest = new GetBlogPostPropertiesRequest();
                getBlogRequest.Data.IncludeHtmlContent = true;
                getBlogRequest.Data.IncludeAccessRules = true;
                getBlogRequest.Data.IncludeMetaData    = true;
                getBlogRequest.Data.IncludeTags        = true;
                var blog = api.Blog.BlogPost.Properties.Get(getBlogRequest);
                api.Blog.BlogPost.Properties.Post(blog.ToPostRequest());
                api.Blog.BlogPost.Properties.Put(blog.ToPutRequest());
                api.Blog.BlogPost.Properties.Delete(new DeleteBlogPostPropertiesRequest());
                var author = api.Blog.Author.Get(new GetAuthorRequest());
                api.Blog.Authors.Post(author.ToPostRequest());
                api.Blog.Author.Put(author.ToPutRequest());
                api.Blog.Author.Delete(new DeleteAuthorRequest());
                var settings = api.Blog.Settings.Get(new GetBlogPostsSettingsRequest());
                api.Blog.Settings.Put(settings.ToPutRequest());

                // Sitemap:
                var sitemap = api.Pages.SitemapNew.Get(new GetSitemapRequest());
                api.Pages.Sitemaps.Post(sitemap.ToPostRequest());
                api.Pages.SitemapNew.Put(sitemap.ToPutRequest());
                api.Pages.SitemapNew.Delete(new DeleteSitemapRequest());

                // Sitemap nodes:
                var node = api.Pages.SitemapNew.Node.Get(new GetNodeRequest());
                api.Pages.SitemapNew.Nodes.Post(node.ToPostRequest());
                api.Pages.SitemapNew.Node.Put(node.ToPutRequest());
                api.Pages.SitemapNew.Node.Delete(new DeleteNodeRequest());

                // Destroyed draft (should be called on event BetterCms.Events.PageEvents.Instance.ContentDraftDestroyed)
                var destroyDraftRequest = new DestroyContentDraftRequest();
                // destroyDraftRequest.ContentId = contentId;
                api.Pages.Content.Draft.Delete(destroyDraftRequest);
            }
        }
        public GetPagePropertiesResponse Get(GetPagePropertiesRequest request)
        {
            var query = repository.AsQueryable<Module.Pages.Models.PageProperties>();

            if (request.PageId.HasValue)
            {
                query = query.Where(page => page.Id == request.PageId.Value);
            }
            else
            {
                var url = urlService.FixUrl(request.PageUrl);
                query = query.Where(page => page.PageUrl == url);
            }

            var response = query
                .Select(page => new GetPagePropertiesResponse
                    {
                        Data = new PagePropertiesModel
                            {
                                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.Empty,
                                CategoryId = page.Category != null && !page.Category.IsDeleted ? page.Category.Id : (Guid?)null,
                                IsArchived = page.IsArchived,
                                MainImageId = page.Image != null && !page.Image.IsDeleted ? page.Image.Id : (Guid?)null,
                                FeaturedImageId = page.FeaturedImage != null && !page.FeaturedImage.IsDeleted ?  page.FeaturedImage.Id : (Guid?)null,
                                SecondaryImageId = page.SecondaryImage != null && !page.SecondaryImage.IsDeleted ? page.SecondaryImage.Id : (Guid?)null,
                                CustomCss = page.CustomCss,
                                CustomJavaScript = page.CustomJS,
                                UseCanonicalUrl = page.UseCanonicalUrl,
                                UseNoFollow = page.UseNoFollow,
                                UseNoIndex = page.UseNoIndex
                            },
                        MetaData = request.Data.IncludeMetaData
                            ? new MetadataModel
                            {
                                MetaTitle = page.MetaTitle,
                                MetaDescription = page.MetaDescription,
                                MetaKeywords = page.MetaKeywords
                            }
                            : null,
                        Category = page.Category != null && !page.Category.IsDeleted && request.Data.IncludeCategory
                            ? new CategoryModel
                            {
                                Id = page.Category.Id,
                                Version = page.Category.Version,
                                CreatedBy = page.Category.CreatedByUser,
                                CreatedOn = page.Category.CreatedOn,
                                LastModifiedBy = page.Category.ModifiedByUser,
                                LastModifiedOn = page.Category.ModifiedOn,
                                Name = page.Category.Name
                            } : null,
                        Layout = request.Data.IncludeLayout && !page.Layout.IsDeleted
                            ? new LayoutModel
                            {
                                Id = page.Layout.Id,
                                Version = page.Layout.Version,
                                CreatedBy = page.Layout.CreatedByUser,
                                CreatedOn = page.Layout.CreatedOn,
                                LastModifiedBy = page.Layout.ModifiedByUser,
                                LastModifiedOn = page.Layout.ModifiedOn,

                                Name = page.Layout.Name,
                                LayoutPath = page.Layout.LayoutPath,
                                PreviewUrl = page.Layout.PreviewUrl
                            }
                            : null,
                        MainImage = page.Image != null && !page.Image.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.Image.Id,
                                Version = page.Image.Version,
                                CreatedBy = page.Image.CreatedByUser,
                                CreatedOn = page.Image.CreatedOn,
                                LastModifiedBy = page.Image.ModifiedByUser,
                                LastModifiedOn = page.Image.ModifiedOn,

                                Title = page.Image.Title,
                                Caption = page.Image.Caption,
                                Url = page.Image.PublicUrl,
                                ThumbnailUrl = page.Image.PublicThumbnailUrl
                            }
                            : null,
                        FeaturedImage = page.FeaturedImage != null && !page.FeaturedImage.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.FeaturedImage.Id,
                                Version = page.FeaturedImage.Version,
                                CreatedBy = page.FeaturedImage.CreatedByUser,
                                CreatedOn = page.FeaturedImage.CreatedOn,
                                LastModifiedBy = page.FeaturedImage.ModifiedByUser,
                                LastModifiedOn = page.FeaturedImage.ModifiedOn,

                                Title = page.FeaturedImage.Title,
                                Caption = page.FeaturedImage.Caption,
                                Url = page.FeaturedImage.PublicUrl,
                                ThumbnailUrl = page.FeaturedImage.PublicThumbnailUrl
                            }
                            : null,
                        SecondaryImage = page.SecondaryImage != null && !page.SecondaryImage.IsDeleted && request.Data.IncludeImages
                            ? new ImageModel
                            {
                                Id = page.SecondaryImage.Id,
                                Version = page.SecondaryImage.Version,
                                CreatedBy = page.SecondaryImage.CreatedByUser,
                                CreatedOn = page.SecondaryImage.CreatedOn,
                                LastModifiedBy = page.SecondaryImage.ModifiedByUser,
                                LastModifiedOn = page.SecondaryImage.ModifiedOn,

                                Title = page.SecondaryImage.Title,
                                Caption = page.SecondaryImage.Caption,
                                Url = page.SecondaryImage.PublicUrl,
                                ThumbnailUrl = page.SecondaryImage.PublicThumbnailUrl
                            }
                            : null
                    })
                .FirstOne();

            if (request.Data.IncludeTags)
            {
                response.Tags = LoadTags(response.Data.Id);
            }

            if (request.Data.IncludePageContents)
            {
                response.PageContents = LoadPageContents(response.Data.Id);
            }

            if (request.Data.IncludePageOptions)
            {
                // Get layout options, page options and merge them
                var layoutOptions = repository
                    .AsQueryable<LayoutOption>(lo => lo.Layout.Id == response.Data.LayoutId).ToList();
                var pageOptions = repository
                    .AsQueryable<PageOption>(p => p.Page.Id == response.Data.Id)
                    .ToList();

                response.PageOptions = optionService
                    .GetMergedOptionValuesForEdit(layoutOptions, pageOptions)
                    .Select(o => new OptionModel
                            {
                                Key = o.OptionKey,
                                Value = o.OptionValue,
                                DefaultValue = o.OptionDefaultValue,
                                Type = ((Root.OptionType)(int)o.Type)
                            })
                    .ToList();
            }

            return response;
        }