Ejemplo n.º 1
0
        public async Task <IElementView <PageHeaderElementSettings, PageHeaderElementContent> > ReadElementViewAsync(long tenantId, long elementId, IPageContext context)
        {
            PageHeaderElementSettings settings = await _elementRepository.ReadElementSettingsAsync(tenantId, elementId);

            if (settings == null)
            {
                return(null);
            }

            Page page = await _pageService.ReadPageAsync(tenantId, context.PageId);

            PageHeaderElementContent content = new PageHeaderElementContent();

            content.Created        = settings.ShowCreated ? (DateTime?)page.Created : null;
            content.Updated        = settings.ShowUpdated && !(settings.ShowCreated && (page.Created.Date == page.Updated.Date)) ? (DateTime?)page.Updated : null;
            content.Occurred       = settings.ShowOccurred && page.Occurred.HasValue ? page.Occurred : null;
            content.OccursInFuture = content.Occurred.HasValue && (page.Occurred.Value.Date > DateTime.UtcNow.Date);
            content.Name           = settings.ShowName ? page.Name : null;
            content.Description    = settings.ShowDescription ? page.Description : null;

            if (settings.ShowImage && page.ThumbnailImageBlobId.HasValue)
            {
                BlobImage thumbnailImage = (BlobImage)await _storageService.ReadBlobAsync(tenantId, page.ThumbnailImageBlobId.Value);

                content.Image = new PageHeaderImage
                {
                    BlobId = thumbnailImage.BlobId,
                    PageId = page.PageId,
                    Height = thumbnailImage.Height,
                    Width  = thumbnailImage.Width
                };
            }

            if (settings.ShowBreadcrumbs)
            {
                IEnumerable <Page> pages = await _pageService.ListPagesInHierarchyAsync(tenantId, context.PageId);

                content.Breadcrumbs = pages.Reverse().Select(p => new PageHeaderBreadcrumb
                {
                    Home     = p.ParentPageId == null,
                    Name     = p.Name,
                    PageId   = p.PageId,
                    PageName = p.Name
                });
            }

            return(new ElementView <PageHeaderElementSettings, PageHeaderElementContent>
            {
                Settings = settings,
                Content = content
            });
        }
        public async Task <PageHeaderElementContent> ReadElementContentAsync(long tenantId, long elementId, long pageId)
        {
            PageHeaderElementSettings elementSettings = await _elementRepository.ReadElementSettingsAsync(tenantId, elementId);

            Page page = await _pageService.ReadPageAsync(tenantId, pageId);

            if (elementSettings.ShowBreadcrumbs)
            {
                PopulatePageHierarchy(page);
            }

            return(new PageHeaderElementContent
            {
                Page = page
            });
        }