Exemple #1
0
        /// <summary>
        /// Populates the properties of <see cref="BaseViewModel" />
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="content">The content.</param>
        /// <param name="contentExperimentSettingsService">The content experiment settings service.</param>
        /// <param name="inUmbracoPreviewMode">if set to <c>true</c> [in umbraco preview mode].</param>
        /// <exception cref="System.ArgumentNullException">model
        /// or
        /// content</exception>
        public void PopulateBaseViewModel(BaseViewModel model, IPublishedContent content, IContentExperimentSettingsService contentExperimentSettingsService, bool inUmbracoPreviewMode)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            model.BreadcrumbProvider = new UmbracoBreadcrumbProvider();

            model.Metadata.Title = content.Name;
            model.Metadata.Title = new RemoveUmbracoNumericSuffixFilter().Apply(model.Metadata.Title);

            model.Metadata.PageUrl      = new Uri(content.UrlAbsolute());
            model.Metadata.Description  = content.GetPropertyValue <string>("pageDescription");
            model.PageType              = content.DocumentTypeAlias;
            model.Metadata.SystemId     = content.Id.ToString(CultureInfo.InvariantCulture);
            model.Metadata.DateCreated  = content.CreateDate.ToIso8601Date();
            model.Metadata.DateModified = content.UpdateDate.ToIso8601Date();
            var expiryDate = content.GetPropertyValue <DateTime>("unpublishAt");

            if (expiryDate != DateTime.MinValue)
            {
                model.Metadata.DateReview = expiryDate.ToIso8601Date();
            }

            model.IsPublicView = !inUmbracoPreviewMode && model.Metadata.PageUrl.Host.ToUpperInvariant() != "LOCALHOST";
            if (contentExperimentSettingsService != null)
            {
                model.ContentExperimentPageSettings = contentExperimentSettingsService.LookupSettingsForPage(content.Id);
            }
        }
Exemple #2
0
        /// <summary>
        /// Populates the properties of <see cref="BaseViewModel" />
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="content">The content.</param>
        /// <param name="contentExperimentSettingsService">The content experiment settings service.</param>
        /// <param name="expiryDate">The expiry date of the page.</param>
        /// <param name="inUmbracoPreviewMode">if set to <c>true</c> [in umbraco preview mode].</param>
        /// <param name="skinService">The skin service.</param>
        /// <exception cref="ArgumentNullException">model
        /// or
        /// content</exception>
        /// <exception cref="System.ArgumentNullException">model
        /// or
        /// content</exception>
        public async tasks.Task <bool> PopulateBaseViewModel(Models.BaseViewModel model, IPublishedContent content, IContentExperimentSettingsService contentExperimentSettingsService, DateTime?expiryDate, bool inUmbracoPreviewMode, ISkinToApplyService skinService = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            model.BreadcrumbProvider = new UmbracoBreadcrumbProvider();

            if (String.IsNullOrEmpty(model.Metadata.Title))
            {
                model.Metadata.Title = content.Name;
                model.Metadata.Title = new RemoveUmbracoNumericSuffixFilter().Apply(model.Metadata.Title);
            }
            model.Metadata.PageUrl = new Uri(content.UrlAbsolute());
            if (String.IsNullOrEmpty(model.Metadata.Description))
            {
                model.Metadata.Description = content.GetPropertyValue <string>("pageDescription") ?? String.Empty;
            }
            model.PageType              = content.DocumentTypeAlias;
            model.Metadata.SystemId     = content.Id.ToString(CultureInfo.InvariantCulture);
            model.Metadata.DateCreated  = content.CreateDate.ToIso8601Date();
            model.Metadata.DateModified = content.UpdateDate.ToIso8601Date();

            if (expiryDate.HasValue && expiryDate != DateTime.MinValue && expiryDate != DateTime.MaxValue)
            {
                model.Metadata.DateReview = expiryDate.ToIso8601Date();
            }

            model.IsPublicView = !inUmbracoPreviewMode && model.Metadata.PageUrl.Host.ToUpperInvariant() != "LOCALHOST";
            if (contentExperimentSettingsService != null)
            {
                model.ContentExperimentPageSettings = contentExperimentSettingsService.LookupSettingsForPage(content.Id);
            }

            if (_templateRequest != null)
            {
                try
                {
                    model.WebChat = await _templateRequest.RequestWebChatSettingsAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // Catch and report exceptions - don't throw them and cause the page to fail
                    ex.ToExceptionless().Submit();
                }
                try
                {
                    model.TemplateHtml = await _templateRequest.RequestTemplateHtmlAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // Catch and report exceptions - don't throw them and cause the page to fail
                    ex.ToExceptionless().Submit();
                }
            }

            if (skinService != null)
            {
                model.SkinToApply = skinService.LookupSkinForPage(content);
            }

            // Return a value (any value) so that this async method can be run synchronously by the controller for Umbraco Forms
            return(true);
        }