Example #1
0
        public async Task <PageSeoOptions> GetPageSeoOptionsAsync(IPage page, CancellationToken cancellationToken = default)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            var result = new PageSeoOptions
            {
                Title       = await pageRepositiry.GetPageTitleAsync(page, cancellationToken),
                Description = await pageRepositiry.GetPageDescriptionAsync(page, cancellationToken),
                Keywords    = await pageRepositiry.GetPageKeywordsAsync(page, cancellationToken)
            };

            return(result);
        }
Example #2
0
        public async Task UpdatePageSeoOptionsAsync(IPage page, PageSeoOptions seoOptions, CancellationToken cancellationToken = default)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }
            if (seoOptions == null)
            {
                throw new ArgumentNullException(nameof(seoOptions));
            }

            await pageRepositiry.SetPageTitleAsync(page, seoOptions.Title);

            await pageRepositiry.SetPageDescriptionAsync(page, seoOptions.Description);

            await pageRepositiry.SetPageKeywordsAsync(page, seoOptions.Keywords);

            await pageRepositiry.UpdatePageAsync(page, cancellationToken);
        }
        protected override async Task OnPageRequestAsync(PageRequestContext context)
        {
            PageService = HttpContext.RequestServices.GetRequiredService <IPageService>();

            if (Request.Query.TryGetValue("editId", out string editIdValue))
            {
                if (!Guid.TryParse(editIdValue, out Guid editId))
                {
                    context.Result = BadRequest();
                    return;
                }

                var pageEditingService = HttpContext.RequestServices.GetRequiredService <IPageContentService>();
                editSession = await pageEditingService.FindEditByIdAsync(editId);

                if (editSession == null)
                {
                    context.Result = NotFound();
                    return;
                }

                page = await PageService.FindPageByIdAsync(editSession.PageId);

                if (page == null)
                {
                    context.Result = NotFound();
                    return;
                }

                var accessProvider = HttpContext.RequestServices.GetRequiredService <Identity.IAccessProvider>();

                if (!await accessProvider.CheckAccessAsync() || await accessProvider.GetUserIdAsync() != editSession.UserId)
                {
                    var pageLinkGenerator = HttpContext.RequestServices.GetRequiredService <IPageLinkGenerator>();

                    context.Result = RedirectPermanent(await pageLinkGenerator.GetPathAsync(page));
                    return;
                }
            }
            else
            {
                var routeData = RouteData;

                var pagePath = string.Empty;
                if (routeData.Values.TryGetValue("url", out object urlValue) && urlValue != null)
                {
                    pagePath = (string)urlValue;
                }

                var url = await PageService.FindPageUrlAsync(pagePath);

                if (url == null)
                {
                    context.Result = NotFound();
                    return;
                }

                if (url.PageId.HasValue)
                {
                    page = await PageService.FindPageByIdAsync(url.PageId.Value);

                    if (page == null)
                    {
                        context.Result = NotFound();
                        return;
                    }

                    if (!page.IsPublished)
                    {
                        var accessProvider = HttpContext.RequestServices.GetRequiredService <Identity.IAccessProvider>();
                        if (!await accessProvider.CheckAccessAsync())
                        {
                            context.Result = NotFound();
                            return;
                        }
                    }
                }
                else
                {
                    var pageLinkGenerator = HttpContext.RequestServices.GetRequiredService <IPageLinkGenerator>();
                    var redirectUrl       = await pageLinkGenerator.GetPathAsync(url.Redirect.Path);

                    if (url.Redirect.IsPermament)
                    {
                        context.Result = RedirectPermanent(redirectUrl);
                    }
                    else
                    {
                        context.Result = Redirect(redirectUrl);
                    }
                    return;
                }
            }

            PageMetadata = await PageService.GetPageTypeAsync(page, HttpContext.RequestAborted);

            pageSeo = await PageService.GetPageSeoOptionsAsync(page, HttpContext.RequestAborted);

            if (editSession != null)
            {
                var pageEditingService = HttpContext.RequestServices.GetRequiredService <IPageContentService>();
                PageContent = await pageEditingService.GetContentAsync(editSession, HttpContext.RequestAborted);
            }
            else
            {
                PageContent = await PageService.GetPageContentAsync(page, HttpContext.RequestAborted);
            }
            if (PageContent == null)
            {
                throw new InvalidOperationException();
            }

            ContentContext = new ContentContext(page, PageContent, HttpContext.RequestServices, editSession != null);

            Status       = page.IsPublished ? Models.PageStatus.Published : Models.PageStatus.Draft;
            ParentPageId = await PageService.GetParentPageIdAsync(page, HttpContext.RequestAborted);
        }