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?
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:
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 :)
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?
Hi Glen.
Here is a basic code example on how to first create a content and then a member assosiated to that content node.
In this little video I have hooked this code example into my "ContentPublishing"-event just as an example of how it will work:
Hope this was helpful!
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 :)
is working on a reply...