示例#1
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)
                        {
                            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);
        }
		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;
		}
示例#3
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;
		}