Example #1
0
        public ActionResult NewContentPage(string schemaId, string editContentHeading)
        {
            // Create a new Content Page to be passed to the edit content action
            var page = GetDefaultContentPage();

            // If a schema was passed in, we will want to assign that schema id to the newly created page
            // We will also want to copy over html from an existing page that uses that html. That way the user has a consistent editor.
            ApplySchema(page, schemaId);

            Context.ContentPages.Add(page);
            Context.SaveChanges();

            // Update the page title / permalink with the new id we now have
            page.DisplayName = "Page " + page.ContentPageId;
            page.Title       = "Page " + page.ContentPageId;
            page.HTMLContent = ContentUtils.ReplacePageParametersInHtmlContent(page.HTMLUnparsed, page);

            AddNewPageExtension(page);


            Context.SaveChanges();
            CachedObjects.GetCacheContentPages(true);

            // Pass content Heading along if it exists
            object routeParameters = new { id = page.ContentPageId };

            if (!String.IsNullOrEmpty(editContentHeading))
            {
                routeParameters = new { id = page.ContentPageId, schema = schemaId, editContentHeading };
            }

            return(RedirectToAction("EditContent", "Pages", routeParameters));
        }
Example #2
0
        protected void SetContentPageData(ContentPage editedContent, PageDetails entity, bool isRevision, bool isBasic, DateTime?publishDate)
        {
            Mapper.Map <PageDetails, ContentPage>(entity, editedContent);

            if (isRevision)
            {
                editedContent.IsRevision          = true;
                editedContent.ParentContentPageId = entity.ContentPageId;
            }
            else
            {
                editedContent.IsRevision          = false;
                editedContent.ParentContentPageId = null;
            }

            editedContent.DraftAuthorName = UserUtils.CurrentMembershipUsername();
            editedContent.WasPublished    = publishDate.HasValue;
            editedContent.PublishDate     = publishDate ?? DateTime.UtcNow;
            editedContent.HTMLContent     = ContentUtils.ReplacePageParametersInHtmlContent(editedContent.HTMLContent, entity);
        }
Example #3
0
        public JsonResult AddNewPageFromTemplate(string templatePath, string viewTemplate, string permalink, string title, int parent)
        {
            var result         = new JsonResult();
            var contentUtility = new ContentUtils();

            // check to see if permalink exists
            if (contentUtility.CheckPermalink(permalink, 0, parent))
            {
                result.Data = new
                {
                    success = false,
                    message = "Permalink is already in use."
                };
                return(result);
            }

            var urlLink = "";
            var page    = new ContentPage
            {
                Title                  = title,
                IsActive               = false,
                CreateDate             = DateTime.UtcNow,
                Permalink              = permalink,
                DisplayName            = permalink,
                ParentNavigationItemId = parent,
                Template               = !String.IsNullOrEmpty(viewTemplate) ? viewTemplate.ToLower() : "blank",
                HTMLUnparsed           = ContentUtils.RenderPartialViewToString(templatePath, null, ControllerContext, ViewData, TempData),
                HTMLContent            = ContentUtils.RenderPartialViewToString(templatePath, null, ControllerContext, ViewData, TempData)
            };

            try
            {
                Context.ContentPages.Add(page);
                Context.SaveChanges();

                page.HTMLContent = ContentUtils.ReplacePageParametersInHtmlContent(page.HTMLUnparsed, page);
                Context.SaveChanges();
            }
            catch (Exception)
            {
                result.Data = new
                {
                    success = false,
                    message = "Page could not be created."
                };
                return(result);
            }

            CachedObjects.GetCacheContentPages(true);

            var parentHref = NavigationUtils.GetNavItemUrl(parent);

            if (!String.IsNullOrEmpty(parentHref))
            {
                urlLink = parentHref + page.Permalink;
            }

            urlLink     = string.IsNullOrEmpty(urlLink) ? "/" + page.Permalink : urlLink;
            result.Data = new
            {
                id      = page.ContentPageId,
                url     = urlLink,
                success = true,
                message = "Page created, redirecting."
            };

            return(result);
        }