Exemplo n.º 1
0
        private void AppendAttributeValues(Entity entity, ToSicEavAttributeSets attributeSet, Dictionary <string, object> values, string valuesLanguage, bool valuesReadOnly, bool resolveHyperlink)
        {
            foreach (var value in values)
            {
                // Handle special attributes (for example of the system)
                if (value.Key.ToLower() == Constants.EntityFieldIsPublished)
                {
                    entity.IsPublished = value.Value as bool? ?? true;
                    continue;
                }

                // Ignore entity guid - it's already set earlier
                if (value.Key.ToLower() == Constants.EntityFieldGuid)
                {
                    continue;
                }

                // Handle content-type attributes
                var attribute = attributeSet.AttributeByName(value.Key);
                if (attribute != null)
                {
                    entity.Attributes.AddValue(attribute.StaticName, value.Value.ToString(), attribute.Type, valuesLanguage, valuesReadOnly, resolveHyperlink);
                }
            }
        }
Exemplo n.º 2
0
        private static Dictionary <string, object> RemoveUnknownFields(Dictionary <string, object> values, ToSicEavAttributeSets attributeSet)
        {
            // todo: ensure things like IsPublished and EntityGuid don't get filtered...
            // part of https://github.com/2sic/2sxc/issues/1173
            var listAllowed  = attributeSet.GetAttributes();
            var allowedNames = listAllowed.Select(a => a.StaticName.ToLower()).ToList();

            allowedNames.Add(Constants.EntityFieldGuid);
            allowedNames.Add(Constants.EntityFieldIsPublished);
            values = values.Where(x => allowedNames.Any(y => y == x.Key.ToLower()))
                     .ToDictionary(x => x.Key, y => y.Value);
            return(values);
        }