public PublishedMember(
            IMember member,
            PublishedContentType publishedMemberType,
            IUmbracoContextAccessor umbracoContextAccessor)
            : base(umbracoContextAccessor)
        {
            _member              = member ?? throw new ArgumentNullException(nameof(member));
            _membershipUser      = member;
            _publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));

            // RawValueProperty is used for two things here
            // - for the 'map properties' thing that we should really get rid of
            // - for populating properties that every member should always have, and that we force-create
            //   if they are not part of the member type properties - in which case they are created as
            //   simple raw properties - which are completely invariant

            var _properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties,
                                                              (t, v) => new RawValueProperty(t, this, v ?? string.Empty));

            var properties = new List <IPublishedProperty>();

            foreach (var propertyType in _publishedMemberType.PropertyTypes)
            {
                var property = _member.Properties[propertyType.Alias];
                if (property == null)
                {
                    continue;
                }

                //properties.Add(new FooProperty(propertyType, this, property.Values));
            }
            EnsureMemberProperties(properties);
            _properties = properties.ToArray();
        }
Exemplo n.º 2
0
        public void DetachedProperty1()
        {
            var type = new PublishedPropertyType("detached", Constants.PropertyEditors.IntegerAlias);
            var prop = PublishedProperty.GetDetached(type.Detached(), "5548");

            Assert.IsInstanceOf <int>(prop.Value);
            Assert.AreEqual(5548, prop.Value);
        }
Exemplo n.º 3
0
        public void CreatedDetachedContentInConverterSample()
        {
            // the converter args
            PublishedPropertyType argPropertyType = null;
            bool argPreview = false;

            var    pt1  = new PublishedPropertyType("legend", 0, Constants.PropertyEditors.TextboxAlias);
            var    pt2  = new PublishedPropertyType("image", 0, Constants.PropertyEditors.MediaPickerAlias);
            string val1 = "";
            int    val2 = 0;

            var c = new ImageWithLegendModel(
                PublishedProperty.GetDetached(pt1.Nested(argPropertyType), val1, argPreview),
                PublishedProperty.GetDetached(pt2.Nested(argPropertyType), val2, argPreview));
        }
Exemplo n.º 4
0
 public void CreateDetachedContentSample()
 {
     bool previewing = false;
     var  t          = PublishedContentType.Get(PublishedItemType.Content, "detachedSomething");
     var  values     = new Dictionary <string, object>();
     var  properties = t.PropertyTypes.Select(x =>
     {
         object value;
         if (values.TryGetValue(x.PropertyTypeAlias, out value) == false)
         {
             value = null;
         }
         return(PublishedProperty.GetDetached(x.Detached(), value, previewing));
     });
     // and if you want some sort of "model" it's up to you really...
     var c = new DetachedContent(properties);
 }
        public MemberPublishedContent(IMember member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            _member              = member;
            _membershipUser      = member;
            _publishedMemberType = PublishedContentType.Get(PublishedItemType.Member, _member.ContentTypeAlias);
            if (_publishedMemberType == null)
            {
                throw new InvalidOperationException("Could not get member type with alias " + _member.ContentTypeAlias);
            }

            _properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties,
                                                          (t, v) => new RawValueProperty(t, v ?? string.Empty))
                          .ToArray();
        }
 public PublishedContent(PublishedContentType contentType, PublishedProperty[] properties)
 {
     _contentType = contentType;
     _properties = properties;
 }