public static webModel.ProductAssociation ToWebModel(this moduleModel.ProductAssociation association, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.ProductAssociation();

            retVal.InjectFrom(association);
            retVal.Tags = association.Tags;
            if (association.AssociatedObject != null)
            {
                var product  = association.AssociatedObject as moduleModel.CatalogProduct;
                var category = association.AssociatedObject as moduleModel.Category;
                if (product != null)
                {
                    var associatedProduct = product.ToWebModel(blobUrlResolver);
                    retVal.AssociatedObjectImg  = associatedProduct.ImgSrc;
                    retVal.AssociatedObjectName = associatedProduct.Name;
                }
                if (category != null)
                {
                    var associatedCategory = category.ToWebModel(blobUrlResolver);
                    retVal.AssociatedObjectImg  = associatedCategory.ImgSrc;
                    retVal.AssociatedObjectName = associatedCategory.Name;
                }
            }

            return(retVal);
        }
예제 #2
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbAssociation"></param>
        /// <returns></returns>
        public static coreModel.ProductAssociation ToCoreModel(this dataModel.Association dbAssociation)
        {
            if (dbAssociation == null)
            {
                throw new ArgumentNullException("dbAssociation");
            }

            var retVal = new coreModel.ProductAssociation
            {
                Type               = dbAssociation.AssociationType,
                Priority           = dbAssociation.Priority,
                AssociatedObjectId = dbAssociation.AssociatedItemId ?? dbAssociation.AssociatedCategoryId,
                Quantity           = dbAssociation.Quantity
            };

            if (dbAssociation.AssociatedCategory != null)
            {
                retVal.AssociatedObject     = dbAssociation.AssociatedCategory.ToCoreModel();
                retVal.AssociatedObjectType = "category";
            }
            if (dbAssociation.AssociatedItem != null)
            {
                //Need to remove associations in associated product to prevent StackOverflow in converter
                dbAssociation.AssociatedItem.Associations = new NullCollection <dataModel.Association>();
                retVal.AssociatedObject     = dbAssociation.AssociatedItem.ToCoreModel();
                retVal.AssociatedObjectType = "product";
            }
            if (!dbAssociation.Tags.IsNullOrEmpty())
            {
                retVal.Tags = dbAssociation.Tags.Split(';');
            }
            return(retVal);
        }
예제 #3
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="association"></param>
        /// <returns></returns>
        public static dataModel.Association ToDataModel(this coreModel.ProductAssociation association)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            var retVal = new dataModel.Association
            {
                Priority        = association.Priority,
                AssociationType = association.Type,
                Quantity        = association.Quantity
            };

            if (association.AssociatedObjectType.EqualsInvariant("product"))
            {
                retVal.AssociatedItemId = association.AssociatedObjectId;
            }
            else if (association.AssociatedObjectType.EqualsInvariant("category"))
            {
                retVal.AssociatedCategoryId = association.AssociatedObjectId;
            }

            if (!association.Tags.IsNullOrEmpty())
            {
                retVal.Tags = string.Join(";", association.Tags);
            }
            return(retVal);
        }
 public static moduleModel.ProductAssociation ToModuleModel(this webModel.ProductAssociation association)
 {
     var retVal = new moduleModel.ProductAssociation();
     retVal.InjectFrom(association);
     retVal.AssociatedProductId = association.ProductId;
     return retVal;
 }
        public static webModel.ProductAssociation ToWebModel(this moduleModel.ProductAssociation association, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.ProductAssociation();

            //Do not use omu.InjectFrom for performance reasons

            retVal.AssociatedObjectId   = association.AssociatedObjectId;
            retVal.AssociatedObjectType = association.AssociatedObjectType;
            retVal.Quantity             = association.Quantity;
            retVal.Tags     = association.Tags;
            retVal.Type     = association.Type;
            retVal.Priority = association.Priority;
            retVal.Tags     = association.Tags;

            if (association.AssociatedObject != null)
            {
                var product  = association.AssociatedObject as moduleModel.CatalogProduct;
                var category = association.AssociatedObject as moduleModel.Category;
                if (product != null)
                {
                    var associatedProduct = product.ToWebModel(blobUrlResolver);
                    retVal.AssociatedObjectImg  = associatedProduct.ImgSrc;
                    retVal.AssociatedObjectName = associatedProduct.Name;
                }
                if (category != null)
                {
                    var associatedCategory = category.ToWebModel(blobUrlResolver);
                    retVal.AssociatedObjectImg  = associatedCategory.ImgSrc;
                    retVal.AssociatedObjectName = associatedCategory.Name;
                }
            }

            return(retVal);
        }
        public static moduleModel.ProductAssociation ToCoreModel(this webModel.ProductAssociation association)
        {
            var retVal = new moduleModel.ProductAssociation();

            retVal.InjectFrom(association);
            retVal.Tags = association.Tags;
            return(retVal);
        }
        public static moduleModel.ProductAssociation ToModuleModel(this webModel.ProductAssociation association)
        {
            var retVal = new moduleModel.ProductAssociation();

            retVal.InjectFrom(association);
            retVal.AssociatedProductId = association.ProductId;
            return(retVal);
        }
        public static webModel.ProductAssociation ToWebModel(this moduleModel.ProductAssociation association, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.ProductAssociation();

            retVal.InjectFrom(association);
            if (association.AssociatedProduct != null)
            {
                var associatedProduct = association.AssociatedProduct.ToWebModel(blobUrlResolver);
                retVal.ProductId   = associatedProduct.Id;
                retVal.ProductCode = associatedProduct.Code;
                retVal.ProductImg  = associatedProduct.ImgSrc;
                retVal.ProductName = associatedProduct.Name;
            }
            return(retVal);
        }
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.ProductAssociation ToCoreModel(this dataModel.Association dbAssociation)
		{
			if (dbAssociation == null)
				throw new ArgumentNullException("dbAssociation");

            var retVal = new coreModel.ProductAssociation
            {
                Name = dbAssociation.AssociationGroup.Name,
                Description = dbAssociation.AssociationGroup.Description,
                Priority = dbAssociation.Priority,
                AssociatedProductId = dbAssociation.CatalogItem.Id,
                Type = dbAssociation.AssociationType,
                AssociatedProduct = dbAssociation.CatalogItem.ToCoreModel()
            };
			return retVal;
		}
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.Association ToDataModel(this coreModel.ProductAssociation association)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            var retVal = new dataModel.Association
            {
                ItemId          = association.AssociatedProductId,
                Priority        = association.Priority,
                AssociationType = association.Type ?? "optional"
            };

            return(retVal);
        }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.ProductAssociation ToCoreModel(this dataModel.Association dbAssociation, coreModel.CatalogProduct associatedProduct)
        {
            if (dbAssociation == null)
            {
                throw new ArgumentNullException("dbAssociation");
            }

            var retVal = new coreModel.ProductAssociation
            {
                Name                = dbAssociation.AssociationGroup.Name,
                Description         = dbAssociation.AssociationGroup.Description,
                Priority            = dbAssociation.Priority,
                AssociatedProductId = associatedProduct.Id,
                Type                = dbAssociation.AssociationType,
                AssociatedProduct   = associatedProduct
            };

            return(retVal);
        }
예제 #12
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbAssociation"></param>
        /// <returns></returns>
        public static coreModel.ProductAssociation ToCoreModel(this dataModel.Association dbAssociation, dataModel.Catalog[] allCatalogs, dataModel.Category[] allCategories)
        {
            if (dbAssociation == null)
            {
                throw new ArgumentNullException("dbAssociation");
            }

            var retVal = new coreModel.ProductAssociation
            {
                Type               = dbAssociation.AssociationType,
                Priority           = dbAssociation.Priority,
                AssociatedObjectId = dbAssociation.AssociatedItemId ?? dbAssociation.AssociatedCategoryId,
                Quantity           = dbAssociation.Quantity
            };

            if (dbAssociation.AssociatedCategoryId != null)
            {
                retVal.AssociatedObject     = allCategories.First(x => x.Id == dbAssociation.AssociatedCategoryId).ToCoreModel(allCatalogs, allCategories);
                retVal.AssociatedObjectType = "category";
            }
            if (dbAssociation.AssociatedItem != null)
            {
                retVal.AssociatedObject = new coreModel.CatalogProduct
                {
                    Id         = dbAssociation.AssociatedItem.Id,
                    CategoryId = dbAssociation.AssociatedItem.CategoryId,
                    CatalogId  = dbAssociation.AssociatedItem.CatalogId,
                    Code       = dbAssociation.AssociatedItem.Code,
                    Name       = dbAssociation.AssociatedItem.Name,
                    Images     = dbAssociation.AssociatedItem.Images != null?dbAssociation.AssociatedItem.Images.Select(x => x.ToCoreModel()).ToList() : null
                };
                retVal.AssociatedObjectType = "product";
            }
            if (!dbAssociation.Tags.IsNullOrEmpty())
            {
                retVal.Tags = dbAssociation.Tags.Split(';');
            }
            return(retVal);
        }