I'm working on a booking system so that once a particular form has been submitted on my site, it also creates a new node in the back-end for reference. Is it possible to do this only using razor? If not, how can I create this functionality?
I'm currently working with the following code that was suggested to me from the Umbraco documentation (by adding it within the codeblock that runs if send is successful), but my razor script errors:
using umbraco.BusinessLogic; using umbraco.cms.businesslogic.web;
DocumentType dt =DocumentType.GetByAlias("Textpage"); User author =User.GetUser(0); Document doc =Document.MakeNew("My new document", dt, author,1018);
I'm using Umbraco v4.7.1.1 and get the following error: "The type or namespace name 'DocumentType' could not be found (are you missing a using directive or an assembly reference?)".
If I add @'s to the namespaces I get the error: 'System.Security.Principal.IPrincipal' does not contain a definition for 'GetUser' and no extension method 'GetUser' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?).
Does anyone have any idea as to where I'm going wrong?
It might also be worth mentioning that following the same api documentation, I can publish and unpublish nodes using these snippets:
Unpublishing a node @using umbraco.cms.businesslogic.web;
@{ Document doc = new Document(1822); doc.UnPublish(); }
Publishing a node @using umbraco.cms.businesslogic.web;
@{ Document d = new Document(1822); d.Publish(new umbraco.BusinessLogic.User(0)); umbraco.library.UpdateDocumentCache(d.Id); } However, for whatever reason, the snippet on creating a new node does not work.
var dt = DocumentType.GetByAlias("Bar"); @* Make sure its a valid document type alias *@ if (dt != null) { var author = umbraco.BusinessLogic.User.GetUser(0);
var doc = Document.MakeNew("Comment", dt, author, 1124);
@* Tell umbraco to publish the document *@ doc.Publish(author); umbraco.library.UpdateDocumentCache(doc.Id); } }
Creating a new node using Razor
Hi Everyone,
I'm working on a booking system so that once a particular form has been submitted on my site, it also creates a new node in the back-end for reference. Is it possible to do this only using razor? If not, how can I create this functionality?
I'm currently working with the following code that was suggested to me from the Umbraco documentation (by adding it within the codeblock that runs if send is successful), but my razor script errors:
I'm using Umbraco v4.7.1.1 and get the following error: "The type or namespace name 'DocumentType' could not be found (are you missing a using directive or an assembly reference?)".
If I add @'s to the namespaces I get the error: 'System.Security.Principal.IPrincipal' does not contain a definition for 'GetUser' and no extension method 'GetUser' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?).
Does anyone have any idea as to where I'm going wrong?
Kind Regards,
mmmoustache
It might also be worth mentioning that following the same api documentation, I can publish and unpublish nodes using these snippets:
Unpublishing a node
@using umbraco.cms.businesslogic.web;
@{
Document doc = new Document(1822);
doc.UnPublish();
}
Publishing a node
@using umbraco.cms.businesslogic.web;
@{
Document d = new Document(1822);
d.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(d.Id);
}
However, for whatever reason, the snippet on creating a new node does not work.
Incase anyone else has this issue, here'w how to create a new document with razor.
Taken from: https://gist.github.com/joeriks/877600
is working on a reply...