modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

Is it possible to create new Nodes with Models.Builder? #57

Closed teusch closed 9 years ago

teusch commented 9 years ago

Is it possible to create new Nodes with Models.Builder?

I assume that it is not possible because it depends on different Umbraco libraries? I always get confused between nodes , documents and ContentService.

Supposing it is not possible , would it be a nice idea to have the names of the properties available without having to resort to reflection? I can then use them in the SetValue method (SomeModel.Propertyx.Name)

    var content = cs.CreateContent("jadija", someparentid,SomeModel.ModelTypeAlias, 0);
    content.SetValue(SomeModel.Propertyx.Name, "jadia");

Regards Teus

zpqrtbnk commented 9 years ago

There are two distinct things:

The models created by ModelsBuilder are read-only, front-end models, meant to make it easier to render content by adding strongly typed properties to the default front-end content objects.

The recommended, official, proper way to create and edit content (aka nodes, document, whatever, but really now it's "content") is therefore to use the content service and then, you are right, you have to resort to magic strings eg SetValue("prop", 1234).

It may make sense, in the future, to have these magic constants generated too, but it's outside the scope of the models builder project ;-)

Making sense?

teusch commented 9 years ago

Thanks, makes a lot of sense! Good to know what the scope is and that I didn't miss an obvious solution.

I will resort to a constants file or look into reflection to keep some sort of consistency.

Regards, Teus

zpqrtbnk commented 9 years ago

Good.