Ejemplo n.º 1
0
        public static TextContentViewModel ToView(TextContent Content, string lang, List <ContentProperty> Properties)
        {
            if (Content == null)
            {
                return(null);
            }
            TextContentViewModel model = new TextContentViewModel();

            model.Id            = Content.Id;
            model.ParentId      = Content.ParentId;
            model.FolderId      = Content.FolderId;
            model.ContentTypeId = Content.ContentTypeId;
            model.UserKey       = Content.UserKey;
            model.LastModified  = Content.LastModified;
            model.Order         = Content.Order;
            model.Online        = Content.Online;
            model.Embedded      = Content.Embedded;
            model.CreationDate  = Content.CreationDate;

            var langcontent = Content.GetContentStore(lang);

            if (langcontent != null)
            {
                model.Values = langcontent.FieldValues;
            }

            if (Properties != null)
            {
                foreach (var item in Properties.Where(o => !o.IsSystemField && !o.MultipleLanguage))
                {
                    if (!model.Values.ContainsKey(item.Name) || string.IsNullOrEmpty(model.Values[item.Name]))
                    {
                        bool found = false;
                        foreach (var citem in Content.Contents)
                        {
                            foreach (var fielditem in citem.FieldValues)
                            {
                                if (fielditem.Key == item.Name)
                                {
                                    model.Values[item.Name] = fielditem.Value;
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 2
0
        public static TextContentViewModel ToListDisplayView(TextContent Content, ContentType ContentType, string lang = null)
        {
            Dictionary <string, string> displayFields = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var fields = ContentType.Properties.FindAll(o => o.IsSummaryField && !o.IsSystemField);

            if (fields == null || fields.Count() == 0)
            {
                fields = ContentType.Properties.FindAll(o => !o.IsSystemField && o.DataType == Data.Definition.DataTypes.String);
            }

            if (fields == null || fields.Count() == 0)
            {
                fields = ContentType.Properties.FindAll(o => !o.IsSystemField);
            }

            foreach (var item in fields)
            {
                if (!displayFields.ContainsKey(item.Name))
                {
                    displayFields.Add(item.Name, item.DisplayName);
                }
            }


            if (Content == null)
            {
                return(null);
            }
            TextContentViewModel model = new TextContentViewModel();

            model.Id            = Content.Id;
            model.ParentId      = Content.ParentId;
            model.FolderId      = Content.FolderId;
            model.ContentTypeId = Content.ContentTypeId;
            model.UserKey       = Content.UserKey;
            model.LastModified  = Content.LastModified;
            model.Order         = Content.Order;
            model.Online        = Content.Online;
            model.Embedded      = Content.Embedded;
            model.CreationDate  = Content.CreationDate;

            var content = Content.GetContentStore(lang);

            if (content != null)
            {
                foreach (var item in content.FieldValues)
                {
                    if (displayFields.ContainsKey(item.Key))
                    {
                        var displayname = displayFields[item.Key];

                        model.Values[displayname] = item.Value;
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Content.UserKey))
                {
                    var userKeyField = ContentType.Properties.Find(o => o.Name == "UserKey");
                    model.Values[userKeyField.DisplayName] = Content.UserKey;
                }
            }
            return(model);
        }