コード例 #1
0
		/// <summary>
		/// Converting to foundation type
		/// </summary>
		/// <param name="catalog"></param>
		/// <returns></returns>
		public static dataModel.Item ToDataModel(this coreModel.CatalogProduct product)
		{
			var retVal = new dataModel.Product();
			var id = retVal.Id;
			retVal.InjectFrom(product);
			if (product.Id == null)
			{
				retVal.Id = id;
			}

			if(product.StartDate == default(DateTime))
			{
				retVal.StartDate = DateTime.UtcNow;
			}

			retVal.IsActive = product.IsActive ?? true;
			retVal.IsBuyable = product.IsBuyable ?? true;
			retVal.TrackInventory = product.TrackInventory ?? true;
			retVal.MaxQuantity = product.MaxQuantity ?? 0;
			retVal.MinQuantity = product.MinQuantity ?? 0;

			retVal.ParentId = product.MainProductId;
			//Constant fields
			//Only for main product
			retVal.AvailabilityRule = (int)coreModel.AvailabilityRule.Always;
			retVal.MinQuantity = 1;
			retVal.MaxQuantity = 0;

			retVal.CatalogId = product.CatalogId;
			retVal.CategoryId = String.IsNullOrEmpty(product.CategoryId) ? null : product.CategoryId;

			#region ItemPropertyValues
			if (product.PropertyValues != null)
			{
				retVal.ItemPropertyValues = new ObservableCollection<dataModel.ItemPropertyValue>();
				foreach (var propValue in product.PropertyValues)
				{
					var dbPropValue = propValue.ToDataModel<dataModel.ItemPropertyValue>() as dataModel.ItemPropertyValue;
					retVal.ItemPropertyValues.Add(dbPropValue);
					dbPropValue.ItemId = retVal.Id;
				}
			}
			#endregion

			#region Assets
			if (product.Assets != null)
			{
				retVal.Assets = new ObservableCollection<dataModel.Asset>(product.Assets.Select(x => x.ToDataModel()));
			}
			#endregion

			#region Images
			if (product.Images != null)
			{
				retVal.Images = new ObservableCollection<dataModel.Image>(product.Images.Select(x => x.ToDataModel()));
			}
			#endregion

			#region Links
			if (product.Links != null)
			{
				retVal.CategoryLinks = new ObservableCollection<dataModel.CategoryItemRelation>();
				retVal.CategoryLinks.AddRange(product.Links.Select(x => x.ToDataModel(product)));
			}
			#endregion

			#region EditorialReview
			if (product.Reviews != null)
			{
				retVal.EditorialReviews = new ObservableCollection<dataModel.EditorialReview>();
				retVal.EditorialReviews.AddRange(product.Reviews.Select(x => x.ToDataModel(retVal)));
			}
			#endregion

			#region Associations
			if (product.Associations != null)
			{
				retVal.AssociationGroups = new ObservableCollection<dataModel.AssociationGroup>();
				var associations = product.Associations.ToArray();
				for (int order = 0; order < associations.Count(); order++)
				{
					var association = associations[order];
					var associationGroup = retVal.AssociationGroups.FirstOrDefault(x => x.Name == association.Name);
					if (associationGroup == null)
					{
						associationGroup = new dataModel.AssociationGroup
						{
							Name = association.Name,
							Description = association.Description,
							Priority = 1,
						};
						retVal.AssociationGroups.Add(associationGroup);
					}
					var foundationAssociation = association.ToDataModel();
					foundationAssociation.Priority = order;
					associationGroup.Associations.Add(foundationAssociation);
				}
			}
			#endregion

			return retVal;
		}
コード例 #2
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.Item ToDataModel(this coreModel.CatalogProduct product)
        {
            var retVal = new dataModel.Product();
            var id     = retVal.Id;

            retVal.InjectFrom(product);
            if (product.Id == null)
            {
                retVal.Id = id;
            }

            if (product.StartDate == default(DateTime))
            {
                retVal.StartDate = DateTime.UtcNow;
            }

            retVal.IsActive       = product.IsActive ?? true;
            retVal.IsBuyable      = product.IsBuyable ?? true;
            retVal.TrackInventory = product.TrackInventory ?? true;
            retVal.MaxQuantity    = product.MaxQuantity ?? 0;
            retVal.MinQuantity    = product.MinQuantity ?? 0;

            retVal.ParentId = product.MainProductId;
            //Constant fields
            //Only for main product
            retVal.AvailabilityRule = (int)coreModel.AvailabilityRule.Always;
            retVal.MinQuantity      = 1;
            retVal.MaxQuantity      = 0;

            retVal.CatalogId  = product.CatalogId;
            retVal.CategoryId = String.IsNullOrEmpty(product.CategoryId) ? null : product.CategoryId;

            #region ItemPropertyValues
            if (product.PropertyValues != null)
            {
                retVal.ItemPropertyValues = new ObservableCollection <dataModel.ItemPropertyValue>();
                foreach (var propValue in product.PropertyValues)
                {
                    var dbPropValue = propValue.ToDataModel <dataModel.ItemPropertyValue>() as dataModel.ItemPropertyValue;
                    retVal.ItemPropertyValues.Add(dbPropValue);
                    dbPropValue.ItemId = retVal.Id;
                }
            }
            #endregion

            #region Assets
            if (product.Assets != null)
            {
                retVal.Assets = new ObservableCollection <dataModel.Asset>(product.Assets.Select(x => x.ToDataModel()));
            }
            #endregion

            #region Images
            if (product.Images != null)
            {
                retVal.Images = new ObservableCollection <dataModel.Image>(product.Images.Select(x => x.ToDataModel()));
            }
            #endregion

            #region Links
            if (product.Links != null)
            {
                retVal.CategoryLinks = new ObservableCollection <dataModel.CategoryItemRelation>();
                retVal.CategoryLinks.AddRange(product.Links.Select(x => x.ToDataModel(product)));
            }
            #endregion

            #region EditorialReview
            if (product.Reviews != null)
            {
                retVal.EditorialReviews = new ObservableCollection <dataModel.EditorialReview>();
                retVal.EditorialReviews.AddRange(product.Reviews.Select(x => x.ToDataModel(retVal)));
            }
            #endregion

            #region Associations
            if (product.Associations != null)
            {
                retVal.AssociationGroups = new ObservableCollection <dataModel.AssociationGroup>();
                var associations = product.Associations.ToArray();
                for (int order = 0; order < associations.Count(); order++)
                {
                    var association      = associations[order];
                    var associationGroup = retVal.AssociationGroups.FirstOrDefault(x => x.Name == association.Name);
                    if (associationGroup == null)
                    {
                        associationGroup = new dataModel.AssociationGroup
                        {
                            Name        = association.Name,
                            Description = association.Description,
                            Priority    = 1,
                        };
                        retVal.AssociationGroups.Add(associationGroup);
                    }
                    var foundationAssociation = association.ToDataModel();
                    foundationAssociation.Priority = order;
                    associationGroup.Associations.Add(foundationAssociation);
                }
            }
            #endregion

            return(retVal);
        }