Example #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);
        }
        public coreModel.Property GetById(string propertyId)
        {
            coreModel.Property retVal = null;
            using (var repository = _catalogRepositoryFactory())
            {
                var dbProperty = repository.GetPropertiesByIds(new string[] { propertyId }).FirstOrDefault();
                if (dbProperty != null)
                {
                    dataModel.Catalog  dbCatalog  = null;
                    dataModel.Category dbCategory = null;
                    dbCatalog = repository.GetPropertyCatalog(dbProperty.Id);
                    if (dbCatalog == null)
                    {
                        dbCategory = repository.GetPropertyCategory(dbProperty.Id);
                        dbCatalog  = repository.GetCatalogById(dbCategory.CatalogId) as dataModel.Catalog;
                    }

                    var catalog  = dbCatalog.ToCoreModel();
                    var category = dbCategory != null?dbCategory.ToCoreModel(catalog) : null;

                    retVal = dbProperty.ToCoreModel(catalog, category);
                }
            }
            return(retVal);
        }
Example #3
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);
        }
        public coreModel.Property Create(coreModel.Property property)
        {
            if (property.CatalogId == null)
            {
                throw new NullReferenceException("property.CatalogId");
            }

            var dbProperty = property.ToDataModel();

            using (var repository = _catalogRepositoryFactory())
            {
                if (property.CategoryId != null)
                {
                    var dbCategory = repository.GetCategoryById(property.CategoryId);
                    repository.SetCategoryProperty(dbCategory, dbProperty);
                }
                else
                {
                    var dbCatalog = repository.GetCatalogById(property.CatalogId) as dataModel.Catalog;
                    if (dbCatalog == null)
                    {
                        throw new OperationCanceledException("Add property only to catalog");
                    }
                    repository.SetCatalogProperty(dbCatalog, dbProperty);
                }
                repository.Add(dbProperty);
                CommitChanges(repository);
            }
            var retVal = GetById(dbProperty.Id);

            return(retVal);
        }
Example #5
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);
        }
Example #6
0
 private static webModel.FilterProperty ConvertToFilterProperty(Property property, string[] selectedPropertyNames)
 {
     return(new webModel.FilterProperty
     {
         Name = property.Name,
         IsSelected = selectedPropertyNames.Contains(property.Name, StringComparer.OrdinalIgnoreCase),
     });
 }
Example #7
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.Property ToDataModel(this coreModel.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var retVal = new dataModel.Property();

            retVal.InjectFrom(property);

            retVal.PropertyValueType = (int)property.ValueType;
            retVal.IsMultiValue      = property.Multivalue;
            retVal.IsLocaleDependant = property.Multilanguage;
            retVal.IsEnum            = property.Dictionary;
            retVal.IsRequired        = property.Required;
            retVal.TargetType        = property.Type.ToString();

            if (property.Attributes != null)
            {
                retVal.PropertyAttributes = new ObservableCollection <dataModel.PropertyAttribute>();
                foreach (var attribute in property.Attributes)
                {
                    var dbAttribute = attribute.ToDataModel();
                    retVal.PropertyAttributes.Add(dbAttribute);
                }
            }

            if (property.DictionaryValues != null)
            {
                retVal.DictionaryValues = new ObservableCollection <dataModel.PropertyDictionaryValue>();
                foreach (var dictValue in property.DictionaryValues)
                {
                    var dbDictValue = dictValue.ToDataModel();
                    retVal.DictionaryValues.Add(dbDictValue);
                }
            }

            if (property.DisplayNames != null)
            {
                foreach (var displayName in property.DisplayNames.Where(x => !String.IsNullOrEmpty(x.Name)))
                {
                    var attributeName  = "DisplayName" + displayName.LanguageCode;
                    var existAttribute = retVal.PropertyAttributes.FirstOrDefault(x => x.PropertyAttributeName == attributeName);
                    if (existAttribute == null)
                    {
                        existAttribute = new dataModel.PropertyAttribute
                        {
                            PropertyId            = property.Id,
                            PropertyAttributeName = attributeName,
                        };
                        retVal.PropertyAttributes.Add(existAttribute);
                    }
                    existAttribute.PropertyAttributeValue = displayName.Name;
                }
            }
            return(retVal);
        }
Example #8
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.Property ToCoreModel(this dataModel.Property dbProperty, coreModel.Catalog catalog, coreModel.Category category)
        {
            if (dbProperty == null)
            {
                throw new ArgumentNullException("dbProperty");
            }

            var retVal = new coreModel.Property();

            retVal.InjectFrom(dbProperty);
            retVal.Required      = dbProperty.IsRequired;
            retVal.Multivalue    = dbProperty.IsMultiValue;
            retVal.Multilanguage = dbProperty.IsLocaleDependant;
            retVal.Dictionary    = dbProperty.IsEnum;
            retVal.ValueType     = (coreModel.PropertyValueType)dbProperty.PropertyValueType;
            retVal.CatalogId     = catalog.Id;
            retVal.Catalog       = catalog;
            retVal.CategoryId    = category == null ? null : category.Id;
            retVal.Category      = category;

            coreModel.PropertyType propertyType;
            if (!string.IsNullOrEmpty(dbProperty.TargetType) && Enum.TryParse(dbProperty.TargetType, out propertyType))
            {
                retVal.Type = propertyType;
            }

            retVal.DisplayNames = catalog.Languages.Select(x => new PropertyDisplayName {
                LanguageCode = x.LanguageCode
            }).ToList();
            if (dbProperty.PropertyAttributes != null)
            {
                retVal.Attributes = new List <coreModel.PropertyAttribute>();
                retVal.Attributes.AddRange(dbProperty.PropertyAttributes.Select(x => x.ToCoreModel(retVal)));

                //Load display names from attributes
                foreach (var displayNameAttribute in retVal.Attributes.Where(x => x.Name.StartsWith("DisplayName")))
                {
                    var languageCode = displayNameAttribute.Name.Substring("DisplayName".Length);
                    var displayName  = retVal.DisplayNames.FirstOrDefault(x => String.Equals(x.LanguageCode, languageCode, StringComparison.InvariantCultureIgnoreCase));
                    if (displayName != null)
                    {
                        displayName.Name = displayNameAttribute.Value;
                    }
                }
            }

            if (dbProperty.PropertyValues != null)
            {
                retVal.DictionaryValues = new List <coreModel.PropertyDictionaryValue>();
                retVal.DictionaryValues.AddRange(dbProperty.PropertyValues.Select(x => x.ToCoreModel(retVal)));
            }

            return(retVal);
        }
        private AttributeFilter ConvertToAttributeFilter(Property property)
        {
            var values = _propertyService.SearchDictionaryValues(property.Id, null);

            var result = new AttributeFilter
            {
                Key    = property.Name,
                Values = values.Select(ConvertToAttributeFilterValue).ToArray(),
            };

            return(result);
        }
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.Property ToCoreModel(this dataModel.Property dbProperty, coreModel.Catalog catalog, coreModel.Category category)
		{
			if (dbProperty == null)
				throw new ArgumentNullException("dbProperty");

			var retVal = new coreModel.Property();
			retVal.InjectFrom(dbProperty);
			retVal.Required = dbProperty.IsRequired;
			retVal.Multivalue = dbProperty.IsMultiValue;
			retVal.Multilanguage = dbProperty.IsLocaleDependant;
			retVal.Dictionary = dbProperty.IsEnum;
			retVal.ValueType = (coreModel.PropertyValueType)dbProperty.PropertyValueType;
			retVal.CatalogId = catalog.Id;
			retVal.Catalog = catalog;
			retVal.CategoryId = category == null ? null : category.Id;
			retVal.Category = category;

			coreModel.PropertyType propertyType;
			if (!string.IsNullOrEmpty(dbProperty.TargetType) && Enum.TryParse(dbProperty.TargetType, out propertyType))
			{
				retVal.Type = propertyType;
			}

			retVal.DisplayNames = catalog.Languages.Select(x => new PropertyDisplayName { LanguageCode = x.LanguageCode }).ToList();
			if (dbProperty.PropertyAttributes != null)
			{
				retVal.Attributes = new List<coreModel.PropertyAttribute>();
				retVal.Attributes.AddRange(dbProperty.PropertyAttributes.Select(x => x.ToCoreModel(retVal)));

				//Load display names from attributes
				foreach (var displayNameAttribute in retVal.Attributes.Where(x => x.Name.StartsWith("DisplayName")))
				{
					var languageCode = displayNameAttribute.Name.Substring("DisplayName".Length);
					var displayName = retVal.DisplayNames.FirstOrDefault(x => String.Equals(x.LanguageCode, languageCode, StringComparison.InvariantCultureIgnoreCase));
					if(displayName != null)
					{
						displayName.Name = displayNameAttribute.Value;
					}
				}
			
			}

			if (dbProperty.PropertyValues != null)
			{
				retVal.DictionaryValues = new List<coreModel.PropertyDictionaryValue>();
				retVal.DictionaryValues.AddRange(dbProperty.PropertyValues.Select(x => x.ToCoreModel(retVal)));
			}

			return retVal;
		}
Example #11
0
        private AttributeFilter ConvertToAttributeFilter(Property property)
        {
            var values = _propertyService.SearchDictionaryValues(property.Id, null);

            var result = new AttributeFilter
            {
                Key          = property.Name,
                Values       = values.Select(ConvertToAttributeFilterValue).ToArray(),
                IsLocalized  = property.Multilanguage,
                DisplayNames = property.DisplayNames.Select(ConvertToFilterDisplayName).ToArray(),
            };

            return(result);
        }
		public static coreModel.Property ToModuleModel(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.ToModuleModel()).ToList();
			}
			if (property.Attributes != null)
			{
				retVal.Attributes = property.Attributes.Select(x => x.ToModuleModel()).ToList();
			}

			return retVal;
		}
        public coreModel.Property Create(coreModel.Property property)
        {
            if (property.CatalogId == null)
            {
                throw new NullReferenceException("property.CatalogId");
            }

            var dbProperty = property.ToDataModel();

            using (var repository = base.CatalogRepositoryFactory())
            {
                if (property.CategoryId != null)
                {
                    var dbCategory = repository.GetCategoriesByIds(new[] { property.CategoryId }, coreModel.CategoryResponseGroup.Info).FirstOrDefault();
                    if (dbCategory == null)
                    {
                        throw new NullReferenceException("dbCategory");
                    }
                    dbCategory.Properties.Add(dbProperty);
                }
                else
                {
                    var dbCatalog = repository.GetCatalogsByIds(new[] { property.CatalogId }).FirstOrDefault();
                    if (dbCatalog == null)
                    {
                        throw new NullReferenceException("dbCatalog");
                    }
                    dbCatalog.Properties.Add(dbProperty);
                }
                repository.Add(dbProperty);
                CommitChanges(repository);
            }
            var retVal = GetById(dbProperty.Id);

            return(retVal);
        }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.PropertyAttribute ToCoreModel(this dataModel.PropertyAttribute dbAttribute, coreModel.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("dbProperty");
            }

            var retVal = new coreModel.PropertyAttribute();

            retVal.InjectFrom(dbAttribute);

            retVal.Name       = dbAttribute.PropertyAttributeName;
            retVal.Value      = dbAttribute.PropertyAttributeValue;
            retVal.PropertyId = property.Id;
            retVal.Property   = property;

            return(retVal);
        }
        private AttributeFilter ConvertToAttributeFilter(Property property)
        {
            var values = _propertyService.SearchDictionaryValues(property.Id, null);

            var result = new AttributeFilter
            {
                Key = property.Name,
                Values = values.Select(ConvertToAttributeFilterValue).ToArray(),
            };

            return result;
        }
 private static webModel.FilterProperty ConvertToFilterProperty(Property property, string[] selectedPropertyNames)
 {
     return new webModel.FilterProperty
     {
         Name = property.Name,
         IsSelected = selectedPropertyNames.Contains(property.Name, StringComparer.OrdinalIgnoreCase),
     };
 }
Example #17
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.PropertyDictionaryValue ToCoreModel(this dataModel.PropertyValue dbPropValue, coreModel.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var retVal = new coreModel.PropertyDictionaryValue();

            retVal.InjectFrom(dbPropValue);

            retVal.LanguageCode = dbPropValue.Locale;
            retVal.Value        = dbPropValue.ToString();
            retVal.PropertyId   = property.Id;
            retVal.Property     = property;

            return(retVal);
        }
Example #18
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.PropertyValue ToDataModel(this coreModel.PropertyDictionaryValue propDictValue, coreModel.Property property)
        {
            var retVal = new dataModel.PropertyValue
            {
                Locale     = propDictValue.LanguageCode,
                PropertyId = property.Id
            };

            retVal.InjectFrom(propDictValue);

            if (propDictValue.Id != null)
            {
                retVal.Id = propDictValue.Id;
            }
            SetPropertyValue(retVal, property.ValueType, propDictValue.Value);

            return(retVal);
        }
        private AttributeFilter ConvertToAttributeFilter(Property property)
        {
            var values = _propertyService.SearchDictionaryValues(property.Id, null);

            var result = new AttributeFilter
            {
                Key = property.Name,
                Values = values.Select(ConvertToAttributeFilterValue).ToArray(),
                IsLocalized = property.Multilanguage,
                DisplayNames = property.DisplayNames.Select(ConvertToFilterDisplayName).ToArray(),
            };

            return result;
        }