Exemplo n.º 1
0
        private static void Add404ErrorPage(PagesApiContext pagesApi, Layout layout, HtmlContentWidget header, HtmlContentWidget footer)
        {
            var pageRequest = new CreatePageRequest()
            {
                LayoutId = layout.Id,
                PageUrl = Urls.Page404,
                Title = "Page Not Found",
                Description = "Page Not Found",
                Status = PageStatus.Published,
                MetaTitle = "Better CMS page not found meta title",
                MetaDescription = "Better CMS page not found meta description.",
                MetaKeywords = "Better CMS"
            };
            var page = pagesApi.CreatePage(pageRequest);

            AddPageContent(pagesApi, page, header, footer, "<p>Oops! The page you are looking for can not be found.</p>");
        }
Exemplo n.º 2
0
        private static void AddDefaultPage(PagesApiContext pagesApi, Layout layout, HtmlContentWidget header, HtmlContentWidget footer)
        {
            var pageRequest = new CreatePageRequest()
            {
                LayoutId = layout.Id,
                PageUrl = Urls.DefaultPage,
                Title = "Better CMS",
                Description = "Better CMS main page.",
                Status = PageStatus.Published,
                MetaTitle = "Better CMS main page meta title",
                MetaDescription = "Better CMS main page meta description.",
                MetaKeywords = "Better CMS"
            };
            var page = pagesApi.CreatePage(pageRequest);

            AddPageContent(pagesApi, page, header, footer, "<p>Hello world!</p>");
        }
Exemplo n.º 3
0
        private static void Add500ErrorPage(PagesApiContext pagesApi, Layout layout, HtmlContentWidget header, HtmlContentWidget footer)
        {
            var pageRequest = new CreatePageRequest()
            {
                LayoutId = layout.Id,
                PageUrl = Urls.Page500,
                Title = "Internal server error",
                Description = "Internal server error",
                Status = PageStatus.Published,
                MetaTitle = "Better CMS internal server error meta title",
                MetaDescription = "Better CMS internal server error meta description.",
                MetaKeywords = "Better CMS"
            };
            var page = pagesApi.CreatePage(pageRequest);

            AddPageContent(pagesApi, page, header, footer, "<p>Oops! The Web server encountered an unexpected condition that prevented it from fulfilling your request. Please try again later or contact the administrator.</p>");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <returns></returns>
        public PageProperties CreatePage(CreatePageRequest pageDto)
        {
            ValidateRequest(pageDto);
            
            try
            {
                var pageUrl = CreateOrFixPageUrl(pageDto.PageUrl, pageDto.Title);
                
                var layout = Repository.AsProxy<Layout>(pageDto.LayoutId);
                
                MediaImage image;
                if (pageDto.ImageId != null && !pageDto.ImageId.Value.HasDefaultValue())
                {
                    image = Repository.AsProxy<MediaImage>(pageDto.ImageId.Value);
                }
                else
                {
                    image = null;
                }

                Category category;
                if (pageDto.CategoryId != null && !pageDto.CategoryId.Value.HasDefaultValue())
                {
                    category = Repository.AsProxy<Category>(pageDto.CategoryId.Value);
                }
                else
                {
                    category = null;
                }

                UnitOfWork.BeginTransaction();

                var page = pageDto.ToPageProperties();
                page.Layout = layout;
                page.Image = image;
                page.Category = category;
                page.PageUrl = pageUrl;
                if (pageDto.Status == PageStatus.Published)
                {
                    page.PublishedOn = DateTime.Now;
                }

                Repository.Save(page);
                UnitOfWork.Commit();

                // Notifying, that page is created
                Events.OnPageCreated(page);

                return page;
            }
            catch (ValidationException inner)
            {
                var message = string.Format("Failed to create page. Title: {0}, Url: {1}", pageDto.Title, pageDto.PageUrl);
                Logger.Error(message, inner);
                throw new CmsApiException(inner.Message, inner);
            }
            catch (Exception inner)
            {
                var message = string.Format("Failed to create page.");
                Logger.Error(message, inner);
                throw new CmsApiException(message, inner);
            }
        }