Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
		/// <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;
		}
Exemplo n.º 4
0
		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;
		}