Example #1
0
        public JsonResult AddNewPageFromTemplate(string templatePath, string viewTemplate, string permalink, string title, int parent)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing you request."
                }
            };

            // check to see if permalink exists
            if (Context.ContentPages.Any(x => x.Permalink == permalink))
            {
                result.Data = new
                {
                    success = false,
                    message = "Permalink is already in use."
                };
                return(result);
            }

            var success = 0;
            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",
                HTMLContent            = ContentUtils.RenderPartialViewToString(templatePath, null, ControllerContext, ViewData, TempData),
            };

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

            var parentHref = NavigationUtils.GetNavItemUrl(parent);

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

            if (success > 0)
            {
                urlLink     = string.IsNullOrEmpty(urlLink) ? "/" + page.Permalink : urlLink;
                result.Data = new
                {
                    id      = page.ContentPageId,
                    url     = urlLink,
                    success = true,
                    message = "Page created, redirecting."
                };
            }
            return(result);
        }
        private List <NavigationItem> PopulateNavList(List <NavigationItem> items)
        {
            // Populate children recursively
            foreach (var item in items)
            {
                item.Children    = Context.NavigationItems.Where(x => x.ParentNavigationItemId == item.NavigationItemId).OrderBy(x => x.Order).ToList();
                item.Href        = NavigationUtils.GetNavItemUrl(item);
                item.HasChildren = item.Children.Count > 0;

                if (item.HasChildren)
                {
                    PopulateNavList(item.Children);
                }
            }

            return(items);
        }
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);
        }