Beispiel #1
0
        public static webModel.Property ToWebModel(this coreModel.Property property)
        {
            var retVal = new webModel.Property();

            retVal.Id            = property.Id;
            retVal.Name          = property.Name;
            retVal.Required      = property.Required;
            retVal.Type          = property.Type;
            retVal.Multivalue    = property.Multivalue;
            retVal.CatalogId     = property.CatalogId;
            retVal.CategoryId    = property.CategoryId;
            retVal.Dictionary    = property.Dictionary;
            retVal.ValueType     = property.ValueType;
            retVal.Type          = property.Type;
            retVal.Multilanguage = property.Multilanguage;
            retVal.IsInherited   = property.IsInherited;

            retVal.ValueType = property.ValueType;
            retVal.Type      = property.Type;

            if (property.DictionaryValues != null)
            {
                retVal.DictionaryValues = property.DictionaryValues.Select(x => x.ToWebModel()).ToList();
            }

            if (property.Attributes != null)
            {
                retVal.Attributes = property.Attributes.Select(x => x.ToWebModel()).ToList();
            }
            retVal.DisplayNames = property.DisplayNames;

            retVal.ValidationRule = property.ValidationRules.FirstOrDefault()?.ToWebModel();

            return(retVal);
        }
Beispiel #2
0
        public static coreModel.Property ToCoreModel(this webModel.Property property)
        {
            var retVal = new coreModel.Property();

            retVal.InjectFrom(property);
            retVal.ValueType    = (coreModel.PropertyValueType)(int) property.ValueType;
            retVal.Type         = (coreModel.PropertyType)(int) property.Type;
            retVal.DisplayNames = property.DisplayNames;
            if (property.DictionaryValues != null)
            {
                retVal.DictionaryValues = property.DictionaryValues.Select(x => x.ToCoreModel()).ToList();
            }
            if (property.Attributes != null)
            {
                retVal.Attributes = property.Attributes.Select(x => x.ToCoreModel()).ToList();
            }
            if (property.ValidationRule != null)
            {
                retVal.ValidationRules = new List <coreModel.PropertyValidationRule>()
                {
                    property.ValidationRule.ToCoreModel()
                };
            }
            else
            {
                retVal.ValidationRules = new List <coreModel.PropertyValidationRule>();
            }

            return(retVal);
        }
Beispiel #3
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
        {
            var retVal = new webModel.Catalog();

            //Do not use omu.InjectFrom for performance reasons
            retVal.Id         = catalog.Id;
            retVal.Name       = catalog.Name;
            retVal.IsVirtual  = catalog.IsVirtual;
            retVal.Properties = new List <webModel.Property>();

            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values           = new List <webModel.PropertyValue>();
                        webModelProperty.IsManageable     = true;
                        webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    var sort = false;
                    foreach (var propValue in catalog.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                        }
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, catalog.Id, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                            sort = true;
                        }
                        property.Values.Add(propValue);
                    }
                    if (sort)
                    {
                        retVal.Properties = retVal.Properties.OrderBy(x => x.Name).ToList();
                    }
                }
            }
            return(retVal);
        }
Beispiel #4
0
        public IHttpActionResult GetNewCategoryProperty(string categoryId)
        {
            var category = _categoryService.GetById(categoryId, Domain.Catalog.Model.CategoryResponseGroup.Info);
            var retVal   = new webModel.Property
            {
                Id               = Guid.NewGuid().ToString(),
                IsNew            = true,
                CategoryId       = categoryId,
                Category         = category.ToWebModel(),
                CatalogId        = category.CatalogId,
                Catalog          = category.Catalog.ToWebModel(),
                Name             = "new property",
                Type             = moduleModel.PropertyType.Category,
                ValueType        = moduleModel.PropertyValueType.ShortText,
                DictionaryValues = new List <webModel.PropertyDictionaryValue>(),
                Attributes       = new List <webModel.PropertyAttribute>(),
                DisplayNames     = category.Catalog.Languages.Select(x => new moduleModel.PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList()
            };

            CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToCoreModel());

            return(Ok(retVal));
        }
        private static bool AddPropertyValues(IHasProperties product, CatalogModule.Property property)
        {
            bool result;
            var  defaultProperty = product.Properties.FirstOrDefault(p => p.Id.EqualsInvariant(property.Id));

            if (defaultProperty == null)
            {
                result = false;
            }
            else
            {
                if (product.PropertyValues == null)
                {
                    product.PropertyValues = new List <PropertyValue>();
                }

                foreach (var propertyValue in property.Values.Select(value => value.ToCoreModel()))
                {
                    propertyValue.Property     = defaultProperty;
                    propertyValue.PropertyId   = defaultProperty.Id;
                    propertyValue.PropertyName = defaultProperty.Name;
                    product.PropertyValues.Add(propertyValue);
                }

                result = true;
            }

            return(result);
        }
        private bool TrySetOwnProperty(CatalogProduct product, CatalogModule.Property property)
        {
            bool result;
            var  propertyValue = property.Values.FirstOrDefault();
            var  value         = (property.Dictionary && !string.IsNullOrEmpty(propertyValue?.ValueId))
                            ? propertyValue.ValueId
                            : propertyValue?.Value;

            var setter = GetProductPropertySetter(product, property);

            if (setter == null)
            {
                result = false;
            }
            else
            {
                if (value == null && property.Required)
                {
                    var message = $"Property value is missing for required property \"{property.Name}\".";
                    throw new ArgumentException(message);
                }

                var convertedValue = value != null?ConvertValue(property.ValueType, value) : null;

                setter.Invoke(product, new[] { convertedValue });
                result = true;
            }

            return(result);
        }
		public static webModel.Property ToWebModel(this coreModel.Property property)
		{
			var retVal = new webModel.Property();

			retVal.InjectFrom(property);
			retVal.Catalog = property.Catalog.ToWebModel(convertProps: false);
			if (property.Category != null)
			{
				retVal.Category = property.Category.ToWebModel(convertProps: false);
			}
			retVal.ValueType = property.ValueType;
			retVal.Type = property.Type;

			if (property.DictionaryValues != null)
			{
				retVal.DictionaryValues = property.DictionaryValues.Select(x => x.ToWebModel()).ToList();
			}

			if(property.Attributes != null)
			{
				retVal.Attributes = property.Attributes.Select(x => x.ToWebModel()).ToList();
			}
			retVal.DisplayNames = property.DisplayNames;

			return retVal;
		}
Beispiel #8
0
        public static webModel.Property ToWebModel(this coreModel.Property property)
        {
            var retVal = new webModel.Property();

            retVal.InjectFrom(property);
            retVal.Catalog = property.Catalog.ToWebModel(convertProps: false);
            if (property.Category != null)
            {
                retVal.Category = property.Category.ToWebModel(convertProps: false);
            }
            retVal.ValueType = property.ValueType;
            retVal.Type      = property.Type;

            if (property.DictionaryValues != null)
            {
                retVal.DictionaryValues = property.DictionaryValues.Select(x => x.ToWebModel()).ToList();
            }

            if (property.Attributes != null)
            {
                retVal.Attributes = property.Attributes.Select(x => x.ToWebModel()).ToList();
            }
            retVal.DisplayNames = property.DisplayNames;

            return(retVal);
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog = category.Catalog.ToWebModel();
            //Reset properties for size economy
            retVal.Catalog.Properties = null;
            retVal.SeoInfos           = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                foreach (var property in category.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values           = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable     = true;
                    webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            return(retVal);
        }
		public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
		{
			var retVal = new webModel.Category();
			retVal.InjectFrom(category);
			retVal.Catalog = category.Catalog.ToWebModel();
            //Reset properties for size economy
            retVal.Catalog.Properties = null;
			retVal.SeoInfos = category.SeoInfos;
	
			if(category.Parents != null)
			{
				retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
			}
			//For virtual category links not needed
			if (!category.Virtual && category.Links != null)
			{
				retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
			}

            //Need add property for each meta info
            retVal.Properties = new List<webModel.Property>();
            if (convertProps)
            {
                foreach (var property in category.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values = new List<webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
			if (category.Images != null)
			{
				retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
			}
			return retVal;
		}
        private static bool TrySetCustomProperty(IHasProperties product, CatalogModule.Property property)
        {
            bool result;

            if (property.Multivalue || property.Dictionary)
            {
                var propertyValues = product.PropertyValues?.Where(
                    propertyValue => propertyValue.Property != null &&
                    propertyValue.Property.Id.EqualsInvariant(property.Id)).ToArray();

                if (propertyValues.IsNullOrEmpty())
                {
                    // idle
                }
                else
                {
                    if (propertyValues == null)
                    {
                        // idle
                    }
                    else
                    {
                        foreach (var productPropertyValue in propertyValues)
                        {
                            product.PropertyValues?.Remove(productPropertyValue);
                        }
                    }
                }

                result = AddPropertyValues(product, property);
            }
            else
            {
                var productPropertyValue = product.PropertyValues?.FirstOrDefault(
                    propertyValue => propertyValue.Property != null &&
                    propertyValue.Property.Id.EqualsInvariant(property.Id));

                if (productPropertyValue != null)
                {
                    var propertyValue = property.Values.FirstOrDefault();

                    productPropertyValue.Value = propertyValue?.Value;

                    result = true;
                }
                else
                {
                    result = AddPropertyValues(product, property);
                }
            }

            return(result);
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog  = category.Catalog.ToWebModel();
            retVal.SeoInfos = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }
            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (properties != null)
            {
                retVal.Properties = new List <webModel.Property>();
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (category.PropertyValues != null)
            {
                foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
		public static webModel.Category ToWebModel(this moduleModel.Category category, moduleModel.Property[] properties = null)
		{
			var retVal = new webModel.Category();
			retVal.InjectFrom(category);
			retVal.Catalog = category.Catalog.ToWebModel();
			retVal.SeoInfos = category.SeoInfos;
	
			if(category.Parents != null)
			{
				retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
			}
			//For virtual category links not needed
			if (!category.Virtual && category.Links != null)
			{
				retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
			}
			retVal.Properties = new List<webModel.Property>();
			//Need add property for each meta info
			if (properties != null)
			{
				retVal.Properties = new List<webModel.Property>();
				foreach (var property in properties)
				{
					var webModelProperty = property.ToWebModel();
					webModelProperty.Values = new List<webModel.PropertyValue>();
					webModelProperty.IsManageable = true;
					webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Category;
					retVal.Properties.Add(webModelProperty);
				}
			}

			//Populate property values
			if (category.PropertyValues != null)
			{
				foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
				{
					var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
					if (property == null)
					{
						//Need add dummy property for each value without property
						property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
						retVal.Properties.Add(property);
					}
					property.Values.Add(propValue);
				}
			}

			return retVal;
		}
		public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
		{
			var retVal = new webModel.Catalog();
			retVal.InjectFrom(catalog);
			retVal.Properties = new List<webModel.Property>();
			if (catalog.Languages != null)
			{
				retVal.Languages = catalog.Languages.Select(x=>x.ToWebModel()).ToList();
			}

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values = new List<webModel.PropertyValue>();
                        webModelProperty.IsManageable = true;
                        webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    foreach (var propValue in catalog.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                        }
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, catalog.Id, null, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                        }
                       property.Values.Add(propValue);
                    }
                }
            }
			return retVal;
		}
Beispiel #15
0
        public IHttpActionResult Post(webModel.Property property)
        {
            var moduleProperty = property.ToModuleModel();

            if (property.IsNew)
            {
                _propertyService.Create(moduleProperty);
            }
            else
            {
                _propertyService.Update(new moduleModel.Property[] { moduleProperty });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #16
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, bool convertProps = true)
        {
            var retVal = new webModel.Catalog();

            retVal.InjectFrom(catalog);
            retVal.Properties = new List <webModel.Property>();
            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            if (convertProps)
            {
                //Need add property for each meta info
                if (catalog.Properties != null)
                {
                    foreach (var property in catalog.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values           = new List <webModel.PropertyValue>();
                        webModelProperty.IsManageable     = true;
                        webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Catalog;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property for property values
                if (catalog.PropertyValues != null)
                {
                    foreach (var propValue in catalog.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, catalog.Id, null, moduleModel.PropertyType.Catalog);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
            return(retVal);
        }
        private MethodInfo GetProductPropertySetter(CatalogProduct product, CatalogModule.Property property)
        {
            var name = property.Name;

            if (_productProperties.TryGetValue(name, out var result))
            {
                return(result);
            }

            var productType     = product.GetType();
            var productProperty = productType.GetProperty(name);

            result = productProperty?.GetSetMethod();

            _productProperties.Add(name, result);

            return(result);
        }
Beispiel #18
0
        public IHttpActionResult CreateOrUpdateProperty(webModel.Property property)
        {
            var moduleProperty = property.ToCoreModel();

            if (property.IsNew)
            {
                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, moduleProperty);

                _propertyService.Create(moduleProperty);
            }
            else
            {
                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, moduleProperty);

                _propertyService.Update(new[] { moduleProperty });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #19
0
        public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Catalog();

            retVal.InjectFrom(catalog);
            retVal.Properties = new List <webModel.Property>();
            if (catalog.Languages != null)
            {
                retVal.Languages = catalog.Languages.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            if (properties != null)
            {
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Catalog;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (catalog.PropertyValues != null)
            {
                foreach (var propValue in catalog.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, catalog.Id, null, moduleModel.PropertyType.Catalog);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
		public static webModel.Catalog ToWebModel(this moduleModel.Catalog catalog, moduleModel.Property[] properties = null)
		{
			var retVal = new webModel.Catalog();
			retVal.InjectFrom(catalog);
			retVal.Properties = new List<webModel.Property>();
			if (catalog.Languages != null)
			{
				retVal.Languages = catalog.Languages.Select(x=>x.ToWebModel()).ToList();
			}
		
			//Need add property for each meta info
			if (properties != null)
			{
				foreach (var property in properties)
				{
					var webModelProperty = property.ToWebModel();
					webModelProperty.Values = new List<webModel.PropertyValue>();
					webModelProperty.IsManageable = true;
					webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Catalog;
					retVal.Properties.Add(webModelProperty);
				}
			}

			//Populate property values
			if (catalog.PropertyValues != null)
			{
				foreach (var propValue in catalog.PropertyValues.Select(x => x.ToWebModel()))
				{
					var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
					if (property == null)
					{
						//Need add dummy property for each value without property
						property = new webModel.Property(propValue, catalog.Id, null, moduleModel.PropertyType.Catalog);
						retVal.Properties.Add(property);
					}
					property.Values.Add(propValue);
				}
			}

			return retVal;
		}
Beispiel #21
0
        public IHttpActionResult GetNewCatalogProperty(string catalogId)
        {
            var catalog = _catalogService.GetById(catalogId);
            var retVal  = new webModel.Property
            {
                Id               = Guid.NewGuid().ToString(),
                IsNew            = true,
                CatalogId        = catalog.Id,
                Catalog          = catalog.ToWebModel(),
                Name             = "new property",
                Type             = moduleModel.PropertyType.Catalog,
                ValueType        = moduleModel.PropertyValueType.ShortText,
                DictionaryValues = new List <webModel.PropertyDictionaryValue>(),
                Attributes       = new List <webModel.PropertyAttribute>(),
                DisplayNames     = catalog.Languages.Select(x => new moduleModel.PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList()
            };

            return(Ok(retVal));
        }
        public IHttpActionResult GetNewCategoryProperty(string categoryId)
        {
			var category = _categoryService.GetById(categoryId);
			var retVal = new webModel.Property
			{
				Id = Guid.NewGuid().ToString(),
				IsNew = true,
				CategoryId = categoryId,
				Category = category.ToWebModel(),
				CatalogId = category.CatalogId,
				Catalog = category.Catalog.ToWebModel(),
				Name = "new property",
				Type = moduleModel.PropertyType.Category,
				ValueType = moduleModel.PropertyValueType.ShortText,
				DictionaryValues = new List<webModel.PropertyDictionaryValue>(),
				Attributes = new List<webModel.PropertyAttribute>(),
				DisplayNames = category.Catalog.Languages.Select(x => new moduleModel.PropertyDisplayName { LanguageCode = x.LanguageCode }).ToList()
			};

            base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel());

            return Ok(retVal);
        }
        public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.Product();

            retVal.Id                     = product.Id;
            retVal.CatalogId              = product.CatalogId;
            retVal.CategoryId             = product.CategoryId;
            retVal.Code                   = product.Code;
            retVal.CreatedBy              = product.CreatedBy;
            retVal.CreatedDate            = product.CreatedDate;
            retVal.DownloadExpiration     = product.DownloadExpiration;
            retVal.DownloadType           = product.DownloadType;
            retVal.EnableReview           = product.EnableReview;
            retVal.Gtin                   = product.Gtin;
            retVal.HasUserAgreement       = product.HasUserAgreement;
            retVal.Height                 = product.Height;
            retVal.IndexingDate           = product.IndexingDate;
            retVal.IsActive               = product.IsActive;
            retVal.IsBuyable              = product.IsBuyable;
            retVal.Length                 = product.Length;
            retVal.ManufacturerPartNumber = product.ManufacturerPartNumber;
            retVal.MaxNumberOfDownload    = product.MaxNumberOfDownload;
            retVal.MaxQuantity            = product.MaxQuantity;
            retVal.MeasureUnit            = product.MeasureUnit;
            retVal.MinQuantity            = product.MinQuantity;
            retVal.ModifiedBy             = product.ModifiedBy;
            retVal.ModifiedDate           = product.ModifiedDate;
            retVal.Name                   = product.Name;
            retVal.PackageType            = product.PackageType;
            retVal.Priority               = product.Priority;
            retVal.ProductType            = product.ProductType;
            retVal.TaxType                = product.TaxType;
            retVal.TrackInventory         = product.TrackInventory;
            retVal.Vendor                 = product.Vendor;
            retVal.Weight                 = product.Weight;
            retVal.WeightUnit             = product.WeightUnit;
            retVal.Width                  = product.Width;

            retVal.SeoInfos = product.SeoInfos;

            if (!product.Outlines.IsNullOrEmpty())
            {
                //Minimize outline size
                retVal.Outlines = product.Outlines.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Images != null)
            {
                retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Assets != null)
            {
                retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Variations != null)
            {
                retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
                //For nested variations leave only variation properties to decrease resulting JSON
                foreach (var variation in retVal.Variations)
                {
                    if (variation.Properties != null)
                    {
                        variation.Properties = variation.Properties.Where(x => x.Type == moduleModel.PropertyType.Variation).ToList();
                    }
                }
            }

            if (product.Links != null)
            {
                retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Reviews != null)
            {
                retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Associations != null)
            {
                retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.ReferencedAssociations != null)
            {
                retVal.ReferencedAssociations = product.ReferencedAssociations.Select(a => a.ToWebModel(blobUrlResolver)).ToList();
            }
            //Init outline and path
            if (product.Category != null)
            {
                var parents = new List <moduleModel.Category>();
                if (product.Category.Parents != null)
                {
                    parents.AddRange(product.Category.Parents);
                }
                parents.Add(product.Category);

                retVal.Outline = string.Join("/", parents.Select(x => x.Id));
                retVal.Path    = string.Join("/", parents.Select(x => x.Name));
            }

            retVal.TitularItemId = product.MainProductId;

            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (product.Properties != null)
            {
                foreach (var property in product.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values           = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable     = true;
                    webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (product.PropertyValues != null)
            {
                foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                    if (property == null)
                    {
                        property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                    }
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, product.CatalogId, moduleModel.PropertyType.Product);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
		public IHttpActionResult GetNewCatalogProperty(string catalogId)
		{
			var catalog = _catalogService.GetById(catalogId);
			var retVal = new webModel.Property
			{
				Id = Guid.NewGuid().ToString(),
				IsNew = true,
				CatalogId = catalog.Id,
				Catalog = catalog.ToWebModel(),
				Name = "new property",
				Type = moduleModel.PropertyType.Catalog,
				ValueType = moduleModel.PropertyValueType.ShortText,
				DictionaryValues = new List<webModel.PropertyDictionaryValue>(),
				Attributes = new List<webModel.PropertyAttribute>(),
				DisplayNames = catalog.Languages.Select(x => new moduleModel.PropertyDisplayName { LanguageCode = x.LanguageCode }).ToList()
			};

			return Ok(retVal);
		}
        public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.Product();
            retVal.InjectFrom(product);

			retVal.SeoInfos = product.SeoInfos;

            if (product.Catalog != null)
            {
                retVal.Catalog = product.Catalog.ToWebModel();
                //Reset catalog properties and languages for response size economy
                retVal.Catalog.Properties = null;
            }

            if (product.Category != null)
            {
				retVal.Category = product.Category.ToWebModel(blobUrlResolver);
                //Reset  category catalog, properties  for response size economy
                retVal.Category.Catalog = null;
                retVal.Category.Properties = null;
            }

            if (product.Images != null)
            {
				retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

			if(product.Assets != null)
			{
				retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
			}

            if (product.Variations != null)
            {
                retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Links != null)
            {
                retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Reviews != null)
            {
                retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Associations != null)
            {
                retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            //Init parents
            if(product.Category != null)
            {
                retVal.Parents = new List<webModel.Category>();
                if(product.Category.Parents != null)
                {
                    retVal.Parents.AddRange(product.Category.Parents.Select(x => x.ToWebModel()));
                }
                retVal.Parents.Add(product.Category.ToWebModel());
                foreach(var parent in retVal.Parents)
                {
                    //Reset some props to decrease size of resulting json
                    parent.Catalog = null;
                    parent.Properties = null;
                }
            }

            retVal.TitularItemId = product.MainProductId;

            retVal.Properties = new List<webModel.Property>();
            //Need add property for each meta info
            if (product.Properties != null)
            {
                foreach (var property in product.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Category = null;
                    webModelProperty.Values = new List<webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (product.PropertyValues != null)
            {
                foreach (var propValue in product.PropertyValues.Select(x=>x.ToWebModel()))
                {
					var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                    if (property == null)
					{  
						//Need add dummy property for each value without property
						property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return retVal;
        }
        public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Product();
            retVal.InjectFrom(product);

			retVal.SeoInfos = product.SeoInfos;

            if (product.Catalog != null)
            {
                retVal.Catalog = product.Catalog.ToWebModel();
            }

            if (product.Category != null)
            {
				retVal.Category = product.Category.ToWebModel(blobUrlResolver);
            }

            if (product.Images != null)
            {
				retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

			if(product.Assets != null)
			{
				retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
			}

            if (product.Variations != null)
            {
                retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Links != null)
            {
                retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Reviews != null)
            {
                retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Associations != null)
            {
                retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            retVal.TitularItemId = product.MainProductId;

            retVal.Properties = new List<webModel.Property>();
            //Need add property for each meta info
            if (properties != null)
            {
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Category = null;
                    webModelProperty.Values = new List<webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (product.PropertyValues != null)
            {
                foreach (var propValue in product.PropertyValues.Select(x=>x.ToWebModel()))
                {
					var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
					{  
						//Need add dummy property for each value without property
						property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product);
                        retVal.Properties.Add(property);
                    }
					property.Values.Add(propValue);
                }
            }

            return retVal;
        }
Beispiel #27
0
        public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver)
        {
            var retVal = new webModel.Product();

            retVal.InjectFrom(product);

            retVal.SeoInfos = product.SeoInfos;

            if (product.Catalog != null)
            {
                retVal.Catalog = product.Catalog.ToWebModel();
                //Reset catalog properties and languages for response size economy
                retVal.Catalog.Properties = null;
            }

            if (product.Category != null)
            {
                retVal.Category = product.Category.ToWebModel(blobUrlResolver);
                //Reset  category catalog, properties  for response size economy
                retVal.Category.Catalog    = null;
                retVal.Category.Properties = null;
            }

            if (product.Images != null)
            {
                retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Assets != null)
            {
                retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Variations != null)
            {
                retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Links != null)
            {
                retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Reviews != null)
            {
                retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Associations != null)
            {
                retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            //Init parents
            if (product.Category != null)
            {
                retVal.Parents = new List <webModel.Category>();
                if (product.Category.Parents != null)
                {
                    retVal.Parents.AddRange(product.Category.Parents.Select(x => x.ToWebModel()));
                }
                retVal.Parents.Add(product.Category.ToWebModel());
                foreach (var parent in retVal.Parents)
                {
                    //Reset some props to decrease size of resulting json
                    parent.Catalog    = null;
                    parent.Properties = null;
                }
            }

            retVal.TitularItemId = product.MainProductId;

            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (product.Properties != null)
            {
                foreach (var property in product.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Category         = null;
                    webModelProperty.Values           = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable     = true;
                    webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (product.PropertyValues != null)
            {
                foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
        public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Product();

            retVal.InjectFrom(product);

            retVal.SeoInfos = product.SeoInfos;

            if (product.Catalog != null)
            {
                retVal.Catalog = product.Catalog.ToWebModel();
            }

            if (product.Category != null)
            {
                retVal.Category = product.Category.ToWebModel();
            }

            if (product.Assets != null)
            {
                var assetBases = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
                retVal.Images = assetBases.OfType <webModel.ProductImage>().ToList();
                retVal.Assets = assetBases.OfType <webModel.ProductAsset>().ToList();
            }

            if (product.Variations != null)
            {
                retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            if (product.Links != null)
            {
                retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Reviews != null)
            {
                retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList();
            }

            if (product.Associations != null)
            {
                retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            retVal.TitularItemId = product.MainProductId;

            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (properties != null)
            {
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Category     = null;
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (product.PropertyValues != null)
            {
                foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            //Do not use omu.InjectFrom for performance reasons
            retVal.Id           = category.Id;
            retVal.IsActive     = category.IsActive;
            retVal.IsVirtual    = category.IsVirtual;
            retVal.Name         = category.Name;
            retVal.ParentId     = category.ParentId;
            retVal.Path         = category.Path;
            retVal.TaxType      = category.TaxType;
            retVal.CatalogId    = category.CatalogId;
            retVal.Code         = category.Code;
            retVal.CreatedBy    = category.CreatedBy;
            retVal.CreatedDate  = category.CreatedDate;
            retVal.ModifiedBy   = category.ModifiedBy;
            retVal.ModifiedDate = category.ModifiedDate;

            retVal.SeoInfos = category.SeoInfos;
            if (!category.Outlines.IsNullOrEmpty())
            {
                //Minimize outline size
                retVal.Outlines = category.Outlines.Select(x => x.ToWebModel()).ToList();
            }

            //Init outline and path
            var parents = new List <moduleModel.Category>();

            if (category.Parents != null)
            {
                retVal.Outline = string.Join("/", category.Parents.Select(x => x.Id));
                retVal.Path    = string.Join("/", category.Parents.Select(x => x.Name));
            }

            //For virtual category links not needed
            if (!category.IsVirtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                if (!category.Properties.IsNullOrEmpty())
                {
                    foreach (var property in category.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values           = new List <webModel.PropertyValue>();
                        webModelProperty.IsManageable     = true;
                        webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                        }
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            return(retVal);
        }