2
votes

I'm trying to create a booking system within Umbraco, so that once a booking form has been submitted on my site, it also creates a new node in the Umbraco 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?)

2

2 Answers

4
votes

The using statements need to be outside your razor code block:

@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); 
}
1
votes

Instead of using the using statement, try using the complete namespace with the class..

E.g. umbraco.cms.businesslogic.web.DocumentType

Next also try opening the solution in Visual Studio. This way, you will get IntelliSense for the namespaces.