/// <summary>
        /// wp.newPage method
        /// </summary>
        /// <param name="blogId">blogID in string format</param>
        /// <param name="userName">login username</param>
        /// <param name="password">login password</param>
        /// <param name="mwaPage">The mwa page.</param>
        /// <param name="publish">if set to <c>true</c> [publish].</param>
        /// <returns>The new page.</returns>
        internal async Task <string> NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish)
        {
            var currentUser = await GetVerifyUserAsync(userName, password);

            //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.PageCreate))
            //{
            //    throw new MetaWeblogException("11", "User authentication failed");
            //}

            var page = new Page
            {
                Title     = mwaPage.title,
                Content   = mwaPage.description,
                Keywords  = mwaPage.mt_keywords,
                Published = publish,
            };

            if (mwaPage.pageDate != new DateTime())
            {
                page.CreationTime = mwaPage.pageDate;
            }

            page.ParentId = mwaPage.pageParentID;

            await _pageManager.CreateAsync(page);

            return(page.Id.ToString());
        }
Example #2
0
        public async Task <ActionResult> Update(UserPageViewModel model)
        {
            var userContext = _userContextAccessor.GetContext();
            var userId      = userContext.UserId;

            if (ModelState.IsValid)
            {
                var page = model.ProjectTo <Page>();

                if (page.Id != null)
                {
                    await _pageManager.UpdateAsync(page);
                }
                else
                {
                    await _pageManager.CreateAsync(page, userId);

                    model.Id = page.Id;
                }

                return(Ok(model));
            }

            return(BadRequest(ModelState));
        }
Example #3
0
    public async Task CreateAsync_ShouldWorkProperly_WithNonExistingSlug()
    {
        var title   = "My awesome page";
        var slug    = "my-awesome-page";
        var content = "<h1>My Awesome Page</h1><p>This is my awesome page content!</p>";

        var page = await pageManager.CreateAsync(title, slug, content);

        page.ShouldNotBeNull();
        page.Title.ShouldBe(title);
        page.Slug.ShouldBe(slug);
        page.Content.ShouldBe(content);
    }
        public async Task <IActionResult> Create(PageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = model.ToEntity();

                // parse slug
                entity.Slug = entity.GetSeName();

                await _pageManager.CreateAsync(entity);

                AlertSuccess("添加成功。");

                return(RedirectToAction(nameof(List)));
            }

            return(View(model));
        }
        private async Task <bool> AddPage(BlogMlExtendedPost extPost)
        {
            var p = new Page();

            p.Title                = extPost.BlogPost.Title;
            p.CreationTime         = extPost.BlogPost.DateCreated;
            p.LastModificationTime = extPost.BlogPost.DateModified;
            p.Content              = extPost.BlogPost.Content.UncodedText;
            p.Description          = extPost.BlogPost.Excerpt.UncodedText;
            p.Published            = extPost.BlogPost.Approved;

            if (!string.IsNullOrEmpty(extPost.PostUrl))
            {
                // looking for a Slug with patterns such as:
                //    /some-slug.aspx
                //    /some-slug.html
                //    /some-slug
                //
                Match slugMatch = Regex.Match(extPost.PostUrl, @"/([^/\.]+)(?:$|\.[\w]{1,10}$)", RegexOptions.IgnoreCase);
                if (slugMatch.Success)
                {
                    p.Slug = slugMatch.Groups[1].Value.Trim();
                }
            }

            if (string.IsNullOrEmpty(p.Slug))
            {
                p.Slug = p.GetSeName();
            }

            // skip if exists
            if (await _pageManager.FindBySlugAsync(p.Slug) != null)
            {
                return(false);
            }

            await _pageManager.CreateAsync(p);

            return(true);
        }
Example #6
0
        public async Task <ActionResult> Update(PageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var page = model.ProjectTo <Page>();

                if (page.Id != null)
                {
                    await _pageManager.UpdateAsync(page);
                }
                else
                {
                    var userId = _adminContext.UserContext.Principal.GetUserName();
                    await _pageManager.CreateAsync(page, userId);

                    model.Id = page.Id;
                }

                //return await Edit(model.SiteId, model.Id);
                return(Ok(model));
            }

            return(BadRequest(ModelState));
        }