Пример #1
0
        /// <summary>
        /// Builds <see cref="IProductVariantDetachedContent"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="IProductVariantDetachedContent"/>.
        /// </returns>
        public IProductVariantDetachedContent BuildEntity(ProductVariantDetachedContentDto dto)
        {
            var detachedContentType = _detachedContentTypeFactory.Value.BuildEntity(dto.DetachedContentType);

            var values = dto.Values.IsNullOrWhiteSpace()
                             ? Enumerable.Empty <KeyValuePair <string, string> >()
                             : JsonConvert.DeserializeObject <IEnumerable <KeyValuePair <string, string> > >(dto.Values);

            var valuesCollection = new DetachedDataValuesCollection(values);

            var detachedContent = new ProductVariantDetachedContent(
                dto.ProductVariantKey,
                detachedContentType,
                dto.CultureName,
                valuesCollection)
            {
                Key           = dto.Key,
                Slug          = dto.Slug ?? string.Empty,
                TemplateId    = dto.TemplateId ?? 0,
                CanBeRendered = dto.CanBeRendered,
                CreateDate    = dto.CreateDate,
                UpdateDate    = dto.UpdateDate
            };

            detachedContent.ResetDirtyProperties();

            return(detachedContent);
        }
Пример #2
0
        /// <summary>
        /// Builds <see cref="IProductVariantDetachedContent"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="IProductVariantDetachedContent"/>.
        /// </returns>
        public IProductVariantDetachedContent BuildEntity(ProductVariantDetachedContentDto dto)
        {
            var detachedContentType = _detachedContentTypeFactory.Value.BuildEntity(dto.DetachedContentType);

            var values = DetachedContentValuesSerializationHelper.Deserialize(dto.Values);

            var valuesCollection = new DetachedDataValuesCollection(values);

            var detachedContent = new ProductVariantDetachedContent(
                dto.ProductVariantKey,
                detachedContentType,
                dto.CultureName,
                valuesCollection)
            {
                Key           = dto.Key,
                Slug          = dto.Slug ?? string.Empty,
                TemplateId    = dto.TemplateId ?? 0,
                CanBeRendered = dto.CanBeRendered,
                CreateDate    = dto.CreateDate,
                UpdateDate    = dto.UpdateDate
            };

            detachedContent.ResetDirtyProperties();

            return(detachedContent);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductAttribute"/> class.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        public ProductAttribute(string name, string sku)
        {
            Ensure.ParameterNotNullOrEmpty(name, "name");
            Ensure.ParameterNotNullOrEmpty(sku, "sku");

            // This is required so that we can create attributes from the WebApi without a lot of
            // round trip traffic to the db to generate the Key(s).  Key is virtual so also forces
            // this class to be sealed
            Key = Guid.NewGuid();
            HasIdentity = false;
            DetachedDataValues = new DetachedDataValuesCollection();
            Name = name;
            Sku = sku;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductAttribute"/> class.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        public ProductAttribute(string name, string sku)
        {
            Ensure.ParameterNotNullOrEmpty(name, "name");
            Ensure.ParameterNotNullOrEmpty(sku, "sku");

            // This is required so that we can create attributes from the WebApi without a lot of
            // round trip traffic to the db to generate the Key(s).  Key is virtual so also forces
            // this class to be sealed
            Key                = Guid.NewGuid();
            HasIdentity        = false;
            DetachedDataValues = new DetachedDataValuesCollection();
            Name               = name;
            Sku                = sku;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductVariantDetachedContent"/> class.
        /// </summary>
        /// <param name="productVariantKey">
        /// The product variant key.
        /// </param>
        /// <param name="detachedContentType">
        /// The detached content type.
        /// </param>
        /// <param name="cultureName">
        /// The culture name.
        /// </param>
        /// <param name="detachedDataValuesCollection">
        /// The detached data values collection.
        /// </param>
        public ProductVariantDetachedContent(
            Guid productVariantKey,
            IDetachedContentType detachedContentType,
            string cultureName,
            DetachedDataValuesCollection detachedDataValuesCollection)
        {
            Ensure.ParameterCondition(!Guid.Empty.Equals(productVariantKey), "productVariantKey");
            Ensure.ParameterNotNull(detachedContentType, "detachedContentType");
            Ensure.ParameterNotNullOrEmpty(cultureName, "cultureName");

            this.ProductVariantKey = productVariantKey;
            this.DetachedContentType = detachedContentType;
            this.CultureName = cultureName;
            this.DetachedDataValues = detachedDataValuesCollection;
        }
Пример #6
0
        /// <summary>
        ///     Builds the <see cref="IProductAttribute" />.
        /// </summary>
        /// <param name="dto">
        ///     The dto.
        /// </param>
        /// <returns>
        ///     The <see cref="IProductAttribute" />.
        /// </returns>
        public IProductAttribute BuildEntity(ProductAttributeDto dto)
        {
            var values = DetachedContentValuesSerializationHelper.Deserialize(dto.DetachedContentValues);

            var valuesCollection = new DetachedDataValuesCollection(values);

            var attribute = new ProductAttribute(dto.Name, dto.Sku)
            {
                Key                = dto.Key,
                OptionKey          = dto.OptionKey,
                SortOrder          = dto.SortOrder,
                IsDefaultChoice    = dto.IsDefaultChoice,
                DetachedDataValues = valuesCollection,
                UpdateDate         = dto.UpdateDate,
                CreateDate         = dto.CreateDate
            };

            return(attribute);
        }
Пример #7
0
        /// <summary>
        /// Builds the <see cref="IProductAttribute"/>.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <returns>
        /// The <see cref="IProductAttribute"/>.
        /// </returns>
        public IProductAttribute BuildEntity(ProductAttributeDto dto)
        {
            var values = dto.DetachedContentValues.IsNullOrWhiteSpace()
                             ? Enumerable.Empty <KeyValuePair <string, string> >()
                             : JsonConvert.DeserializeObject <IEnumerable <KeyValuePair <string, string> > >(dto.DetachedContentValues);

            var valuesCollection = new DetachedDataValuesCollection(values);

            var attribute = new ProductAttribute(dto.Name, dto.Sku)
            {
                Key                = dto.Key,
                OptionKey          = dto.OptionKey,
                SortOrder          = dto.SortOrder,
                IsDefaultChoice    = dto.IsDefaultChoice,
                DetachedDataValues = valuesCollection,
                UpdateDate         = dto.UpdateDate,
                CreateDate         = dto.CreateDate
            };


            return(attribute);
        }
 /// <summary>
 /// Converts data values collection data into a more easily serializable collection for display classes (back office UI)
 /// </summary>
 /// <param name="dataValues">The <see cref="DetachedDataValuesCollection"/></param>
 /// <returns>An <c>IEnumerable{object}</c></returns>
 internal static IEnumerable <KeyValuePair <string, string> > AsEnumerable(this DetachedDataValuesCollection dataValues)
 {
     return(dataValues.Select(item => new KeyValuePair <string, string>(item.Key, item.Value ?? string.Empty)));
 }