Ejemplo n.º 1
0
        /// <summary>
        /// The to product variant detached content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The <see cref="IProductVariantDetachedContent"/>.
        /// </returns>
        public static IProductVariantDetachedContent ToProductVariantDetachedContent(
            this ProductVariantDetachedContentDisplay display,
            IProductVariantDetachedContent destination)
        {
            destination.Slug          = display.Slug;
            destination.TemplateId    = display.TemplateId;
            destination.CanBeRendered = display.CanBeRendered;

            // Find any detached content items that should be removed
            var validPropertyTypeAliases = display.DetachedDataValues.Select(x => x.Key);
            var removers = destination.DetachedDataValues.Where(x => validPropertyTypeAliases.All(y => y != x.Key));

            foreach (var remove in removers)
            {
                destination.DetachedDataValues.RemoveValue(remove.Key);
            }

            foreach (var item in display.DetachedDataValues)
            {
                if (!item.Key.IsNullOrWhiteSpace())
                {
                    destination.DetachedDataValues.AddOrUpdate(item.Key, item.Value, (x, y) => item.Value);
                }
            }

            return(destination);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Maps <see cref="ProductVariantDetachedContentDisplay"/> to <see cref="IProductVariantDetachedContent"/>.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="productVariantKey">
        /// The product Variant Key.
        /// </param>
        /// <returns>
        /// The <see cref="IProductVariantDetachedContent"/>.
        /// </returns>
        public static IProductVariantDetachedContent ToProductVariantDetachedContent(this ProductVariantDetachedContentDisplay display, Guid productVariantKey)
        {
            var contentType = new DetachedContentType(
                display.DetachedContentType.EntityTypeField.TypeKey,
                display.DetachedContentType.UmbContentType.Key)
            {
                Key         = display.DetachedContentType.Key,
                Name        = display.DetachedContentType.Name,
                Description = display.DetachedContentType.Description
            };

            // Assign the default template
            var templateId = 0;

            if (display.TemplateId == 0 && display.DetachedContentType.UmbContentType.DefaultTemplateId != 0)
            {
                templateId = display.DetachedContentType.UmbContentType.DefaultTemplateId;
            }

            var pvdc = new ProductVariantDetachedContent(productVariantKey, contentType, display.CultureName, new DetachedDataValuesCollection(display.DetachedDataValues))
            {
                TemplateId    = templateId,
                Slug          = display.Slug,
                CanBeRendered = display.CanBeRendered
            };

            if (!display.Key.Equals(Guid.Empty))
            {
                pvdc.Key = display.Key;
            }
            return(pvdc);
        }
        /// <summary>
        /// The to product variant detached content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The <see cref="IProductVariantDetachedContent"/>.
        /// </returns>
        public static IProductVariantDetachedContent ToProductVariantDetachedContent(
            this ProductVariantDetachedContentDisplay display,
            IProductVariantDetachedContent destination)
        {
            destination.Slug          = display.Slug;
            destination.TemplateId    = display.TemplateId;
            destination.CanBeRendered = display.CanBeRendered;

            foreach (var item in display.DetachedDataValues)
            {
                destination.DetachedDataValues.AddOrUpdate(item.Key, item.Value, (x, y) => item.Value);
            }

            return(destination);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes the model
 /// </summary>
 private void Initialize()
 {
     _detachedContentDisplay = this.GetDetachedContentDisplayForCulture();
     _properties = new Lazy<Dictionary<string, IEnumerable<IPublishedProperty>>>(this.BuildProperties);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Changes the current culture.
 /// </summary>
 /// <param name="cultureName">
 /// The culture name.
 /// </param>
 internal void ChangeCulture(string cultureName)
 {
     CultureName = cultureName;
     _detachedContentDisplay = this.GetDetachedContentDisplayForCulture();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// The data values as published properties.
        /// </summary>
        /// <param name="pvd">
        /// The <see cref="ProductVariantDetachedContentDisplay"/>.
        /// </param>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IPublishedProperty}"/>.
        /// </returns>
        public static IEnumerable <IPublishedProperty> DataValuesAsPublishedProperties(this ProductVariantDetachedContentDisplay pvd, PublishedContentType contentType)
        {
            var properties = new List <IPublishedProperty>();

            foreach (var dcv in pvd.DetachedDataValues)
            {
                var    propType = contentType.GetPropertyType(dcv.Key);
                object valObj;
                try
                {
                    valObj = DetachedValuesConverter.Current.ConvertDbForContent(propType, dcv).Value;
                }
                catch
                {
                    valObj = dcv.Value;
                }

                if (propType != null)
                {
                    properties.Add(new DetachedPublishedProperty(propType, valObj));
                }
            }

            return(properties);
        }
        /// <summary>
        /// The data values as published properties.
        /// </summary>
        /// <param name="pvd">
        /// The <see cref="ProductVariantDetachedContentDisplay"/>.
        /// </param>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IPublishedProperty}"/>.
        /// </returns>
        public static IEnumerable <IPublishedProperty> DataValuesAsPublishedProperties(this ProductVariantDetachedContentDisplay pvd, PublishedContentType contentType)
        {
            var properties = new List <IPublishedProperty>();

            foreach (var value in pvd.DetachedDataValues)
            {
                var    propType = contentType.GetPropertyType(value.Key);
                object valObj;
                try
                {
                    valObj = JsonConvert.DeserializeObject <object>(value.Value);
                }
                catch
                {
                    valObj = value.Value.Substring(1, value.Value.Length - 1);
                }

                if (propType != null)
                {
                    properties.Add(new DetachedPublishedProperty(propType, valObj));
                }
            }

            return(properties);
        }