Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Glen 36 posts 168 karma points
    Sep 15, 2016 @ 07:43
    Glen
    0

    Create content using ContentService.

    Hi,

    I have a simple register page, login page, logout page and article page and using MemberService I did create a member, username Dummy and Joe when a member login he/she can access article page and can create a article.

    I want to saved the member Id along with the created article so I can check if the article belongs to that specific member, like a foreign key I guess I'm new to umbraco please correct me... what is the best approach for this?

    enter image description here

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Sep 15, 2016 @ 08:37
    Dennis Adolfi
    102

    Hi Glen.

    Here is a basic code example on how to first create a content and then a member assosiated to that content node.

                   var newContent = ApplicationContext.Current.Services.ContentService.CreateContent(name: "GlenĀ“s content", parentId: 1052, contentTypeAlias: "page", userId: -1);
                    ApplicationContext.Current.Services.ContentService.Save(newContent);
    
                    var newMember = ApplicationContext.Current.Services.MemberService.CreateMember(username: "Glen", email: "[email protected]", name: "Glen", memberTypeAlias: "Member");
                    newMember.SetValue("content", newContent.Id); // In my example, the "content" property for members is a contentpicker.
                    ApplicationContext.Current.Services.MemberService.Save(newMember);
    

    In this little video I have hooked this code example into my "ContentPublishing"-event just as an example of how it will work:

    enter image description here

    Hope this was helpful!

  • Glen 36 posts 168 karma points
    Sep 16, 2016 @ 10:19
    Glen
    0

    Hi Dennis,

    Thanks for the quick response I have a simple question, Let say I did follow your example and it work. And I want to display all of the articles with associated name of a member so the other members would see who created that specific article, In my documenttype Article Page and using Razor with Current Page object to display it all, is this the proper way to do it? or there is another approach for this? What should I do to fetch the content along with the name of the member who created that article? I want the umbraco way :)

Please Sign in or register to post replies

Write your reply to:

Draft