/// <summary>
		/// Patch CatalogLanguage type
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.PropertyAttribute source, dataModel.PropertyAttribute target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

			var patchInjectionPolicy = new PatchInjection<dataModel.PropertyAttribute>(x => x.PropertyAttributeName, x => x.PropertyAttributeValue);
			target.InjectFrom(patchInjectionPolicy, source);
		}
示例#2
0
		/// <summary>
		/// Patch changes
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.Asset source, dataModel.Asset target)
		{
			if (target == null)
				throw new ArgumentNullException("target");
			
			var patchInjectionPolicy = new PatchInjection<dataModel.Asset>(x => x.LanguageCode, x=> x.Name );
			target.InjectFrom(patchInjectionPolicy, source);

		}
示例#3
0
		/// <summary>
		/// Patch changes
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.ItemAsset source, dataModel.ItemAsset target)
		{
			if (target == null)
				throw new ArgumentNullException("target");
			
			var patchInjectionPolicy = new PatchInjection<dataModel.ItemAsset>(x => x.AssetType, x=> x.SortOrder );
			target.InjectFrom(patchInjectionPolicy, source);

		}
		/// <summary>
		/// Patch changes
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.EditorialReview source, dataModel.EditorialReview target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

			var patchInjectionPolicy = new PatchInjection<dataModel.EditorialReview>(x => x.Content, x => x.Locale, x=>x.Source);
			target.InjectFrom(patchInjectionPolicy, source);

		}
        /// <summary>
        /// Patch CatalogLanguage type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.PropertyValue source, dataModel.PropertyValue target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            var newValue = target.ToString();
            if (newValue != null)
                SetPropertyValue(target, (coreModel.PropertyValueType)target.ValueType, target.ToString());
            if (source.KeyValue != null)
                target.KeyValue = source.KeyValue;
        }
		/// <summary>
		/// Patch AssociationGroup type
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.AssociationGroup source, dataModel.AssociationGroup target)
		{
			var patchInjectionPolicy = new PatchInjection<dataModel.AssociationGroup>(x => x.Name, x => x.Description);
			target.InjectFrom(patchInjectionPolicy, source);

			if (!source.Associations.IsNullCollection())
			{
				var associationComparer = AnonymousComparer.Create((dataModel.Association x) => x.ItemId);
				source.Associations.Patch(target.Associations, associationComparer,
										 (sourceAssociation, targetAssociation) => sourceAssociation.Patch(targetAssociation));
			}
		}
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.PropertyValue source, dataModel.PropertyValue target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }


            var patchInjectionPolicy = new PatchInjection<dataModel.PropertyValue>(x => x.BooleanValue, x => x.DateTimeValue,
                                                                                  x => x.DecimalValue, x => x.IntegerValue,
                                                                                  x => x.KeyValue, x => x.LongTextValue, x => x.ShortTextValue);
            target.InjectFrom(patchInjectionPolicy, source);
        }
        /// <summary>
        /// Patch CatalogLanguage type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.PropertyDictionaryValue source, dataModel.PropertyDictionaryValue target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

			var newValue = source.ToString();
            if (newValue != null)
                target.Value = source.Value;
            if (source.Alias != null)
                target.Alias = source.Alias;

           
        }
		/// <summary>
		/// Converting to foundation type
		/// </summary>
		/// <param name="itemAsset">The item asset.</param>
		/// <returns></returns>
		/// <exception cref="System.ArgumentNullException">itemAsset</exception>
		public static dataModel.EditorialReview ToDataModel(this coreModel.EditorialReview review, dataModel.Item product, PrimaryKeyResolvingMap pkMap)
		{
			if (review == null)
				throw new ArgumentNullException("review");

			var retVal = new dataModel.EditorialReview();
            pkMap.AddPair(review, retVal);
            retVal.InjectFrom(review);

			retVal.ItemId = product.Id;
			retVal.Source = review.ReviewType;
			retVal.ReviewState = (int)coreModel.ReviewState.Active;
			retVal.Locale = review.LanguageCode;

			return retVal;
		}
		private static void SetPropertyValue(dataModel.PropertyValueBase retVal, coreModel.PropertyValueType type, string value)
        {
            switch (type)
            {
				case coreModel.PropertyValueType.LongText:
                    retVal.LongTextValue = value;
                    break;
				case coreModel.PropertyValueType.ShortText:
                    retVal.ShortTextValue = value;
                    break;
				case coreModel.PropertyValueType.Number:
                    decimal parsedDecimal;
                    Decimal.TryParse(value, out parsedDecimal);
                    retVal.DecimalValue = parsedDecimal;
                    break;
            }
        }
        private static object GetPropertyValue(dataModel.PropertyValue propertyValue)
        {
            
            switch (propertyValue.ValueType)
            {
                case (int)coreModel.PropertyValueType.Boolean:
                    return propertyValue.BooleanValue;
                case (int)coreModel.PropertyValueType.DateTime:
                    return propertyValue.DateTimeValue;
                case (int)coreModel.PropertyValueType.Number:
                    return propertyValue.DecimalValue;
                case (int)coreModel.PropertyValueType.LongText:
                    return propertyValue.LongTextValue;
                default:
                    return propertyValue.ShortTextValue;
            }

    }
		/// <summary>
		/// Converting to foundation type
		/// </summary>
		/// <param name="itemAsset">The item asset.</param>
		/// <returns></returns>
		/// <exception cref="System.ArgumentNullException">itemAsset</exception>
		public static dataModel.EditorialReview ToDataModel(this coreModel.EditorialReview review, dataModel.Item product)
		{
			if (review == null)
				throw new ArgumentNullException("review");

			var retVal = new dataModel.EditorialReview();
			var id = retVal.Id;
			retVal.InjectFrom(review);
			if(review.Id == null)
			{
				retVal.Id = id;
			}
			retVal.ItemId = product.Id;
			retVal.Source = review.ReviewType;
			retVal.ReviewState = (int)coreModel.ReviewState.Active;
			retVal.Locale = review.LanguageCode;

			return retVal;
		}
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategory">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.Category dbCategory, coreModel.Catalog catalog,
                                                    coreModel.Property[] properties = null,  dataModel.Category[] allParents = null)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			var retVal = new coreModel.Category();
			retVal.InjectFrom(dbCategory);
			retVal.CatalogId = catalog.Id;
			retVal.Catalog = catalog;
			retVal.ParentId = dbCategory.ParentCategoryId;
			retVal.IsActive = dbCategory.IsActive;


			retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
			retVal.Virtual = catalog.Virtual;
			retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();


            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

			//Try to inherit taxType from parent category
			if(retVal.TaxType == null && retVal.Parents != null)
			{
				retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault();
			}

			#region Images
			if (dbCategory.Images != null)
			{
				retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
			}
			#endregion

            return retVal;

        }
示例#14
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategoryBase">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.CategoryBase dbCategoryBase, coreModel.Catalog catalog,
                                                    coreModel.Property[] properties = null,  dataModel.Category[] allParents = null)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			var retVal = new coreModel.Category();
			retVal.InjectFrom(dbCategoryBase);
			retVal.CatalogId = catalog.Id;
			retVal.Catalog = catalog;
			retVal.ParentId = dbCategoryBase.ParentCategoryId;
			retVal.IsActive = dbCategoryBase.IsActive;

            var dbCategory = dbCategoryBase as dataModel.Category;
            if (dbCategory != null)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
                retVal.Virtual = catalog.Virtual;
				retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();
            }

            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

			#region Images
			if (dbCategory.Images != null)
			{
				retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
			}
			#endregion

            return retVal;

        }
示例#15
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
		public static void Patch(this coreModel.Category source, dataModel.Category target, PrimaryKeyResolvingMap pkMap)
        {
            if (target == null)
                throw new ArgumentNullException("target");

			//TODO: temporary solution because partial update replaced not nullable properties in db entity
			if (source.IsActive != null)
				target.IsActive = source.IsActive.Value;
            //Handle three valuable states (null, empty and have value states) for case when need reset catalog or category
            if (source.CatalogId == String.Empty)
                target.CatalogId = null;
            if (source.ParentId == String.Empty)
                target.ParentCategoryId = null;


            var dbSource = source.ToDataModel(pkMap) as dataModel.Category;
			var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
                var patchInjectionPolicy = new PatchInjection<dataModel.Category>(x => x.Code, x => x.Name, x => x.TaxType, x => x.CatalogId, x => x.ParentCategoryId);
                dbTarget.InjectFrom(patchInjectionPolicy, dbSource);

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

				if(!dbSource.OutgoingLinks.IsNullCollection())
				{
					dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
				}

				if (!dbSource.Images.IsNullCollection())
				{
					dbSource.Images.Patch(dbTarget.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
				}
            }
        }
		/// <summary>
		/// Patch changes
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.Property source, dataModel.Property target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

			var patchInjectionPolicy = new PatchInjection<dataModel.Property>(x => x.PropertyValueType, x => x.IsEnum, x => x.IsMultiValue, x => x.IsLocaleDependant,
																			   x => x.IsRequired, x => x.TargetType, x => x.Name);
			target.InjectFrom(patchInjectionPolicy, source);


			//Attributes patch
			if (!source.PropertyAttributes.IsNullCollection())
			{
				var attributeComparer = AnonymousComparer.Create((dataModel.PropertyAttribute x) => x.IsTransient() ?  x.PropertyAttributeName : x.Id);
				source.PropertyAttributes.Patch(target.PropertyAttributes, attributeComparer, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
			}
			//Property dict values
			if (!source.PropertyValues.IsNullCollection())
			{
				source.PropertyValues.Patch(target.PropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
			}
		}
 private static void SetPropertyValue(dataModel.PropertyValue retVal, coreModel.PropertyValueType type, string value)
 {
     switch (type)
     {
         case coreModel.PropertyValueType.LongText:
             retVal.LongTextValue = value;
             break;
         case coreModel.PropertyValueType.ShortText:
             retVal.ShortTextValue = value;
             break;
         case coreModel.PropertyValueType.Number:
             decimal parsedDecimal;
             Decimal.TryParse(value.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out parsedDecimal);
             retVal.DecimalValue = parsedDecimal;
             break;
         case coreModel.PropertyValueType.DateTime:
             retVal.DateTimeValue = DateTime.Parse(value);
             break;
         case coreModel.PropertyValueType.Boolean:
             retVal.BooleanValue = Boolean.Parse(value);
             break;
     }
 }
		/// <summary>
		/// Patch Association type
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this dataModel.Association source, dataModel.Association target)
		{
			var patchInjectionPolicy = new PatchInjection<dataModel.Association>(x => x.Priority);
			target.InjectFrom(patchInjectionPolicy, source);
		}
        public void SetCategoryProperty(dataModel.Category category, dataModel.Property property)
        {
            if (category.PropertySet == null)
            {
                var propertySet = new dataModel.PropertySet
                {
                    Name = category.Name + " property set",
                    TargetType = "Category"
                };
                Add(propertySet);
                category.PropertySetId = propertySet.Id;
            }

            var propertySetProperty = new dataModel.PropertySetProperty
            {
                PropertySetId = category.PropertySetId,
                PropertyId = property.Id
            };
            Add(propertySetProperty);

        }
        public dataModel.Property[] GetAllCategoryProperties(dataModel.Category category)
        {
            var retVal = new List<dataModel.Property>();
            if (category.PropertySet != null)
            {
                retVal.AddRange(category.PropertySet.PropertySetProperties.Select(x => x.Property));
            }
            if (category.ParentCategoryId != null)
            {
                var parentCategory = GetCategoryById(category.ParentCategoryId);
                if (parentCategory != null)
                {
                    retVal.AddRange(GetAllCategoryProperties(parentCategory));
                }
            }

            //Add catalog properties
            if (category.Catalog == null)
            {
                category.Catalog = GetCatalogById(category.CatalogId);
            }
            retVal.AddRange(GetCatalogProperties(category.Catalog));
            return retVal.Distinct().ToArray();
        }
 public dataModel.Property[] GetCatalogProperties(dataModel.CatalogBase catalogBase)
 {
     var retVal = new List<dataModel.Property>();
     var catalog = catalogBase as dataModel.Catalog;
     if (catalog != null)
     {
         if (catalog.PropertySet == null && catalog.PropertySetId != null)
         {
             catalog = GetCatalogById(catalogBase.Id) as dataModel.Catalog;
         }
         if (catalog.PropertySet != null)
         {
             retVal.AddRange(catalog.PropertySet.PropertySetProperties.Select(x => x.Property));
         }
     }
     return retVal.ToArray();
 }
        public dataModel.Category[] GetAllCategoryParents(dataModel.Category category)
        {
            var retVal = new List<dataModel.Category>();

            if (category.ParentCategoryId != null)
            {
                var parentCategory = Categories.FirstOrDefault(x => x.Id == category.ParentCategoryId);
                if (parentCategory != null)
                {
                    retVal.Add(parentCategory);
                    retVal.AddRange(GetAllCategoryParents(parentCategory));
                }
            }
            return retVal.ToArray();
        }
示例#23
0
		/// <summary>
		/// Patch changes
		/// </summary>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public static void Patch(this coreModel.CatalogProduct source, dataModel.Item target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

			//TODO: temporary solution because partial update replaced not nullable properties in db entity
			if (source.IsBuyable != null)
				target.IsBuyable = source.IsBuyable.Value;
			if (source.IsActive != null)
				target.IsActive = source.IsActive.Value;
			if (source.TrackInventory != null)
				target.TrackInventory = source.TrackInventory.Value;
			if (source.MinQuantity != null)
				target.MinQuantity = source.MinQuantity.Value;
			if (source.MaxQuantity != null)
				target.MaxQuantity = source.MaxQuantity.Value;
            //Handle three valuable states (null, empty and have value states) for case when need reset catalog or category
            if (source.CatalogId == String.Empty)
                 target.CatalogId = null;
            if (source.CategoryId == String.Empty)
                target.CategoryId = null;

            var patchInjectionPolicy = new PatchInjection<dataModel.Item>(x => x.Name, x => x.Code, x => x.ManufacturerPartNumber, x => x.Gtin, x => x.ProductType,
                                                                          x => x.WeightUnit, x => x.Weight, x => x.MeasureUnit, x => x.Height, x => x.Length, x => x.Width, x => x.EnableReview, x => x.MaxNumberOfDownload,
                                                                          x => x.DownloadExpiration, x => x.DownloadType, x => x.HasUserAgreement, x => x.ShippingType, x => x.TaxType, x => x.Vendor, x => x.CatalogId, x => x.CategoryId);

            var dbSource = source.ToDataModel();
			target.InjectFrom(patchInjectionPolicy, dbSource);

			#region Assets
			if (!dbSource.Assets.IsNullCollection())
			{
				dbSource.Assets.Patch(target.Assets, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
			}
			#endregion
			#region Images
			if (!dbSource.Images.IsNullCollection())
			{
				dbSource.Images.Patch(target.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
			}
			#endregion

			#region ItemPropertyValues
			if (!dbSource.ItemPropertyValues.IsNullCollection())
			{
				//Need skip inherited properties without overridden value
				if (source.MainProduct != null)
				{
					var dbParent = source.MainProduct.ToDataModel();
					var parentPropValues = dbParent.ItemPropertyValues.ToLookup(x => x.Name + "-" + x.ToString());
					var variationPropValues = dbSource.ItemPropertyValues.ToLookup(x => x.Name + "-" + x.ToString());
					dbSource.ItemPropertyValues = new ObservableCollection<dataModel.ItemPropertyValue>(variationPropValues.Where(x => !parentPropValues.Contains(x.Key)).SelectMany(x => x));
				}

				dbSource.ItemPropertyValues.Patch(target.ItemPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
			}

			#endregion

			#region Links
			if (!dbSource.CategoryLinks.IsNullCollection())
			{
				dbSource.CategoryLinks.Patch(target.CategoryLinks, new CategoryItemRelationComparer(),
										 (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
			}
			#endregion


			#region EditorialReviews
			if (!dbSource.EditorialReviews.IsNullCollection())
			{
				dbSource.EditorialReviews.Patch(target.EditorialReviews, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
			}
			#endregion

			#region Association
			if (!dbSource.AssociationGroups.IsNullCollection())
			{
				var associationComparer = AnonymousComparer.Create((dataModel.AssociationGroup x) => x.Name);
				dbSource.AssociationGroups.Patch(target.AssociationGroups, associationComparer,
										 (sourceGroup, targetGroup) => sourceGroup.Patch(targetGroup));
			}
			#endregion
		}
示例#24
0
        /// <summary>
        /// Patch CatalogBase type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this dataModel.Catalog source, dataModel.Catalog target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            var patchInjectionPolicy = new PatchInjection<dataModel.Catalog>(x => x.Name, x => x.DefaultLanguage);
            target.InjectFrom(patchInjectionPolicy, source);

            //Languages patch
            var sourceCatalog = source as dataModel.Catalog;
            var targetCatalog = target as dataModel.Catalog;
            if (sourceCatalog != null && targetCatalog != null && !sourceCatalog.CatalogLanguages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((dataModel.CatalogLanguage x) => x.Language);
                sourceCatalog.CatalogLanguages.Patch(targetCatalog.CatalogLanguages, languageComparer,
                                                     (sourceLang, targetlang) => sourceLang.Patch(targetlang));
            }

            //Property values
			if (sourceCatalog != null && !sourceCatalog.CatalogPropertyValues.IsNullCollection())
            {
                sourceCatalog.CatalogPropertyValues.Patch(targetCatalog.CatalogPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }


        }
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
		public static void Patch(this coreModel.Category source, dataModel.Category target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

			//TODO: temporary solution because partial update replaced not nullable properties in db entity
			if (source.IsActive != null)
				target.IsActive = source.IsActive.Value;

			var dbSource = source.ToDataModel() as dataModel.Category;
			var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
				var patchInjectionPolicy = new PatchInjection<dataModel.Category>(x => x.Code, x=>x.Name, x=>x.TaxType);
				target.InjectFrom(patchInjectionPolicy, source);

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

				if(!dbSource.OutgoingLinks.IsNullCollection())
				{
					dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
				}

				if (!dbSource.Images.IsNullCollection())
				{
					dbSource.Images.Patch(dbTarget.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
				}
            }
        }