public async Task <string> NewPage(
            string blogId,
            string userName,
            string password,
            PageStruct newPage,
            bool publish)
        {
            var page = mapper.GetPageFromStruct(newPage);

            page.ProjectId = blogId;
            page.Id        = Guid.NewGuid().ToString();
            //page.Author = authorDisplayName;
            page.IsPublished = publish;

            await pageService.Create(
                blogId,
                userName,
                password,
                page,
                publish
                ).ConfigureAwait(false);

            return(page.Id);
        }
Beispiel #2
0
        public async Task <string> NewPage(
            string blogId,
            string userName,
            string password,
            PageStruct newPage,
            bool publish)
        {
            var permission = await _security.ValidatePermissions(
                blogId,
                userName,
                password,
                CancellationToken.None
                ).ConfigureAwait(false);

            if (!permission.CanEditPages)
            {
                _log.LogWarning($"user {userName} cannot edit pages");
                return(null);
            }

            var page = _mapper.GetPageFromStruct(newPage);

            page.ProjectId          = blogId;
            page.Id                 = Guid.NewGuid().ToString();
            page.CreatedByUser      = permission.DisplayName;
            page.LastModifiedByUser = permission.DisplayName;
            if (!string.IsNullOrWhiteSpace(page.ParentId))
            {
                var parent = await _pageService.GetPage(page.ParentId);

                if (parent != null)
                {
                    page.ParentSlug = parent.Slug;
                }
            }
            else
            {
                page.ParentSlug = null;
            }
            if (string.IsNullOrWhiteSpace(newPage.pageOrder))
            {
                page.PageOrder = await _pageService.GetNextChildPageOrder(page.ParentSlug).ConfigureAwait(false);
            }

            if (publish)
            {
                page.IsPublished = true;
                page.PubDate     = DateTime.UtcNow;
            }
            else
            {
                page.DraftAuthor  = page.Author;
                page.DraftContent = page.Content;
                page.Content      = null;
                page.IsPublished  = false;
                page.PubDate      = null;
            }

            var convertToRelativeUrls = true;

            await _pageService.Create(page, convertToRelativeUrls).ConfigureAwait(false);

            _pageService.ClearNavigationCache();
            if (publish)
            {
                await _pageService.FirePublishEvent(page);
            }

            return(page.Id);
        }
        public async Task <string> NewPage(
            string blogId,
            string userName,
            string password,
            PageStruct newPage,
            bool publish)
        {
            var permission = await _security.ValidatePermissions(
                blogId,
                userName,
                password,
                CancellationToken.None
                ).ConfigureAwait(false);

            if (!permission.CanEditPages)
            {
                _log.LogWarning($"user {userName} cannot edit pages");
                return(null);
            }

            var page = _mapper.GetPageFromStruct(newPage);

            page.ProjectId          = blogId;
            page.Id                 = Guid.NewGuid().ToString();
            page.CreatedByUser      = permission.DisplayName;
            page.LastModifiedByUser = permission.DisplayName;
            if (!string.IsNullOrWhiteSpace(page.ParentId))
            {
                var parent = await _pageService.GetPage(page.ParentId).ConfigureAwait(false);

                if (parent != null)
                {
                    page.ParentSlug = parent.Slug;
                }
            }
            else
            {
                page.ParentSlug = null;
            }
            if (string.IsNullOrWhiteSpace(newPage.pageOrder))
            {
                page.PageOrder = await _pageService.GetNextChildPageOrder(page.ParentSlug).ConfigureAwait(false);
            }

            var utcPubDate = _timeZoneHelper.ConvertToUtc(newPage.pageDate, permission.TimeZoneId);

            if (publish)
            {
                if (utcPubDate.Year == 1)
                {
                    //invalid because not supplied
                    utcPubDate = DateTime.UtcNow;
                }

                if (utcPubDate < DateTime.UtcNow)
                {
                    page.IsPublished = true;
                    page.PubDate     = utcPubDate;
                }
                else
                {
                    //future date needs to be draft, it will auto publish after pub date
                    page.DraftAuthor  = page.Author;
                    page.DraftContent = page.Content;
                    page.DraftPubDate = utcPubDate;
                    page.IsPublished  = false;
                    page.PubDate      = null;
                    page.Content      = null;
                }
            }
            else
            {
                page.DraftAuthor  = page.Author;
                page.DraftContent = page.Content;
                if (utcPubDate > DateTime.UtcNow)
                {
                    page.DraftPubDate = utcPubDate;
                }
                page.Content     = null;
                page.IsPublished = false;
                page.PubDate     = null;
            }

            await _pageUrlResolver.ConvertMediaToRelativeUrls(page).ConfigureAwait(false);

            await _pageService.Create(page).ConfigureAwait(false);

            await _navigationCache.ClearTreeCache();

            if (publish)
            {
                await _pageService.FirePublishEvent(page).ConfigureAwait(false);
            }

            return(page.Id);
        }