Esempio n. 1
0
 public void OnHtmlContentCreated(HtmlContent htmlContent)
 {
     if (HtmlContentCreated != null)
     {
         HtmlContentCreated(new SingleItemEventArgs<HtmlContent>(htmlContent));
     }
 }
        /// <summary>
        /// Creates the content of the page HTML.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        /// Page content entity with created HTML content
        /// </returns>
        public PageContent CreatePageHtmlContent(CreatePageHtmlContentRequest request)
        {
            ValidateRequest(request);

            var region = GetRegion(request);

            try
            {
                UnitOfWork.BeginTransaction();

                var content = new HtmlContent
                {
                    Name = request.Name,
                    ActivationDate = request.ActivationDate ?? DateTime.Today,
                    ExpirationDate = TimeHelper.FormatEndDate(request.ExpirationDate),
                    Html = request.Html ?? string.Empty,
                    CustomCss = request.CustomCss,
                    UseCustomCss = !string.IsNullOrWhiteSpace(request.CustomCss),
                    CustomJs = request.CustomJs,
                    UseCustomJs = !string.IsNullOrWhiteSpace(request.CustomJs)
                };

                var contentService = Resolve<IContentService>();
                var contentToSave = contentService.SaveContentWithStatusUpdate(content, request.ContentStatus);

                var pageContent = SavePageContent(request.PageId, region, contentToSave);

                UnitOfWork.Commit();

                return pageContent;
            }
            catch (Exception inner)
            {
                var message = string.Format("Failed to create page HTML content.");
                Logger.Error(message, inner);
                throw new CmsApiException(message, inner);
            }
        }