internal static ProductAttributeDisplay ToProductAttributeDisplay(this IProductAttribute productAttribute, IContentType contentType, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var display = AutoMapper.Mapper.Map <ProductAttributeDisplay>(productAttribute);

            if (contentType == null)
            {
                return(display);
            }
            display.EnsureValueConversion(contentType, conversionType);
            return(display);
        }
 /// <summary>
 /// Updates an attribute.
 /// </summary>
 /// <param name="attribute">
 /// The attribute.
 /// </param>
 internal void Save(IProductAttribute attribute)
 {
     using (new WriteLock(Locker))
     {
         var uow = UowProvider.GetUnitOfWork();
         using (var repository = RepositoryFactory.CreateProductOptionRepository(uow))
         {
             repository.UpdateAttribute(attribute);
             uow.Commit();
         }
     }
 }
Esempio n. 3
0
        private void DeleteProductAttribute(IProductAttribute productAttribute)
        {
            // TODO : this is sort of hacky but we want ProductVariant events to trigger on a ProductVariant Delete
            // and we need to delete all variants that had the attribute that is to be deleted so the current solution
            // is to delete all associations from the merchProductVariant2ProductAttribute table so that the follow up
            // EnsureProductVariantsHaveAttributes called in the ProductVariantService cleans up the orphaned variants and fires off
            // the events

            Database.Execute("DELETE FROM merchProductVariant2ProductAttribute WHERE productVariantKey IN (SELECT productVariantKey FROM merchProductVariant2ProductAttribute WHERE productAttributeKey = @Key)",
                             new { Key = productAttribute.Key });
            Database.Execute("DELETE FROM merchProductAttribute WHERE pk = @Key", new { Key = productAttribute.Key });
        }
Esempio n. 4
0
        private void SaveProductAttribute(IProductAttribute productAttribute)
        {
            var factory = new ProductAttributeFactory();

            if (!productAttribute.HasIdentity)
            {
                //((Entity)productAttribute).AddingEntity();
                productAttribute.CreateDate = DateTime.Now;
                productAttribute.UpdateDate = DateTime.Now;

                var dto = factory.BuildDto(productAttribute);
                Database.Insert(dto);
                productAttribute.Key = dto.Key;
            }
            else
            {
                ((Entity)productAttribute).UpdatingEntity();
                var dto = factory.BuildDto(productAttribute);
                Database.Update(dto);
            }
        }
        internal static IProductAttribute ToProductAttribute(this ProductAttributeDisplay productAttributeDisplay, IProductAttribute destinationProductAttribute)
        {
            if (productAttributeDisplay.Key != Guid.Empty)
            {
                destinationProductAttribute.Key = productAttributeDisplay.Key;
            }
            destinationProductAttribute.Name = productAttributeDisplay.Name;
            destinationProductAttribute.Sku = productAttributeDisplay.Sku;
            destinationProductAttribute.OptionKey = productAttributeDisplay.OptionKey;
            destinationProductAttribute.SortOrder = productAttributeDisplay.SortOrder;

            return destinationProductAttribute;
        }
 /// <summary>
 /// Maps <see cref="IProductAttribute"/> to <see cref="ProductAttributeDisplay"/>.
 /// </summary>
 /// <param name="productAttribute">
 /// The product attribute.
 /// </param>
 /// <returns>
 /// The <see cref="ProductAttributeDisplay"/>.
 /// </returns>
 internal static ProductAttributeDisplay ToProductAttributeDisplay(this IProductAttribute productAttribute)
 {
     return(productAttribute.ToProductAttributeDisplay(null));
 }
        /// <summary>
        /// The to product attribute.
        /// </summary>
        /// <param name="productAttributeDisplay">
        /// The product attribute display.
        /// </param>
        /// <param name="destinationProductAttribute">
        /// The destination product attribute.
        /// </param>
        /// <returns>
        /// The <see cref="IProductAttribute"/>.
        /// </returns>
        internal static IProductAttribute ToProductAttribute(this ProductAttributeDisplay productAttributeDisplay, IProductAttribute destinationProductAttribute)
        {
            if (productAttributeDisplay.Key != Guid.Empty)
            {
                destinationProductAttribute.Key = productAttributeDisplay.Key;
            }

            var validPropertyTypeAliases = productAttributeDisplay.DetachedDataValues.Select(x => x.Key);
            var removeAtts = destinationProductAttribute.DetachedDataValues.Where(x => validPropertyTypeAliases.All(y => y != x.Key));

            foreach (var remove in removeAtts)
            {
                destinationProductAttribute.DetachedDataValues.RemoveValue(remove.Key);
            }

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


            destinationProductAttribute.Name      = productAttributeDisplay.Name;
            destinationProductAttribute.Sku       = productAttributeDisplay.Sku;
            destinationProductAttribute.OptionKey = productAttributeDisplay.OptionKey;
            destinationProductAttribute.SortOrder = productAttributeDisplay.SortOrder;

            return(destinationProductAttribute);
        }
 internal static ProductAttributeDisplay ToProductAttributeDisplay(this IProductAttribute productAttribute)
 {
     return(AutoMapper.Mapper.Map <ProductAttributeDisplay>(productAttribute));
 }
        internal static IProductAttribute ToProductAttribute(this ProductAttributeDisplay productAttributeDisplay, IProductAttribute destinationProductAttribute)
        {
            if (productAttributeDisplay.Key != Guid.Empty)
            {
                destinationProductAttribute.Key = productAttributeDisplay.Key;
            }
            destinationProductAttribute.Name      = productAttributeDisplay.Name;
            destinationProductAttribute.Sku       = productAttributeDisplay.Sku;
            destinationProductAttribute.OptionKey = productAttributeDisplay.OptionKey;
            destinationProductAttribute.SortOrder = productAttributeDisplay.SortOrder;

            return(destinationProductAttribute);
        }
Esempio n. 10
0
        /// <summary>
        /// Updates an attribute.
        /// </summary>
        /// <param name="attribute">
        /// The attribute.
        /// </param>
        internal void Save(IProductAttribute attribute)
        {
            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateProductOptionRepository(uow))
                {

                    repository.UpdateAttribute(attribute);
                    uow.Commit();
                }
            }
        }
        /// <summary>
        /// The to product attribute.
        /// </summary>
        /// <param name="productAttributeDisplay">
        /// The product attribute display.
        /// </param>
        /// <param name="destinationProductAttribute">
        /// The destination product attribute.
        /// </param>
        /// <returns>
        /// The <see cref="IProductAttribute"/>.
        /// </returns>
        internal static IProductAttribute ToProductAttribute(this ProductAttributeDisplay productAttributeDisplay, IProductAttribute destinationProductAttribute)
        {
            if (productAttributeDisplay.Key != Guid.Empty)
            {
                destinationProductAttribute.Key = productAttributeDisplay.Key;
            }

            var validPropertyTypeAliases = productAttributeDisplay.DetachedDataValues.Select(x => x.Key);
            var removeAtts = destinationProductAttribute.DetachedDataValues.Where(x => validPropertyTypeAliases.All(y => y != x.Key));
            foreach (var remove in removeAtts)
            {
                destinationProductAttribute.DetachedDataValues.RemoveValue(remove.Key);
            }

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

            destinationProductAttribute.Name = productAttributeDisplay.Name;
            destinationProductAttribute.Sku = productAttributeDisplay.Sku;
            destinationProductAttribute.OptionKey = productAttributeDisplay.OptionKey;
            destinationProductAttribute.SortOrder = productAttributeDisplay.SortOrder;

            return destinationProductAttribute;
        }
Esempio n. 12
0
 /// <summary>
 /// Performs the work of mapping the value.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{KeyValuePair}"/>.
 /// </returns>
 protected override IEnumerable <KeyValuePair <string, string> > ResolveCore(IProductAttribute source)
 {
     return(source.DetachedDataValues == null?
            Enumerable.Empty <KeyValuePair <string, string> >() :
                source.DetachedDataValues.AsEnumerable());
 }