public static ModelTypeMetaCategory CreateFrom(TemplateSection section)
        {
            var m = new ModelTypeMetaCategory
            {
                Identifier = section.SectionId,
                Fields     = null
            };

            if (section.SectionLabels != null && section.SectionLabels.Any())
            {
                m.Labels = section.SectionLabels;
            }

            var labels = m.Labels ?? new Dictionary <string, string>();

            m.Label = labels.ContainsKey(WebHelper.DefaultLanguage) ? labels[WebHelper.DefaultLanguage] : m.Identifier;

            var templateFields = section.Fields ?? new List <TemplateField>();

            foreach (var templateField in templateFields)
            {
                var categoryField = ModelTypeField.CreateFrom(templateField);
                if (categoryField != null)
                {
                    m.Fields = m.Fields ?? new List <ModelTypeField>();
                    m.Fields.Add(categoryField);
                }
            }

            return(m);
        }
        public static ModelTypeMetaCategory CreateFrom(JProperty property)
        {
            var m = new ModelTypeMetaCategory
            {
                Identifier = property.Name,
                Fields     = null
            };

            var fields = JsonHelper.FindToken(property, ModelData.MetaCategoryFieldsKey);

            if (fields != null)
            {
                foreach (var field in fields.Children())
                {
                    var categoryField = ModelTypeField.CreateFrom(field);
                    if (categoryField != null)
                    {
                        m.Fields = m.Fields ?? new List <ModelTypeField>();
                        m.Fields.Add(categoryField);
                    }
                }
            }

            return(m);
        }
        public static ModelTypeField CreateFrom(TemplateField field)
        {
            var f = new ModelTypeField
            {
                Key        = field.DbFieldName.ToLowerCamelCase(),
                Type       = field.ElasticType,
                Label      = field.FieldLabels.ContainsKey(WebHelper.DefaultLanguage) ? field.FieldLabels[WebHelper.DefaultLanguage] : field.DbFieldName,
                Visibility = field.Visibility ?? (int)DataElementVisibility.@internal,
                Labels     = field.FieldLabels
            };

            f.Name = StringHelper.GetNormalizedKey(f.Key);

            return(f.Key != null ? f : null);
        }
        public static ModelTypeField CreateFrom(string key, string name = null, JToken token = null)
        {
            var f = new ModelTypeField
            {
                Key = key
            };

            if (token != null)
            {
                f.Name       = JsonHelper.FindTokenValue <string>(token, NameTag, true) ?? f.Name;
                f.Type       = JsonHelper.FindTokenValue <string>(token, TypeTag, true);
                f.Label      = JsonHelper.FindTokenValue <string>(token, LabelTag, true);
                f.Visibility = JsonHelper.FindTokenValue <int>(token, VisibilityTag, true);
            }

            if (f.Name == null)
            {
                f.Name = f.Key;
            }

            return(f.Key != null ? f : null);
        }