This project is read-only.

How to create blog dynamically

Topics: Customizing Orchard
Nov 30, 2011 at 9:01 PM


I want to create a blog when a user registered and this new blog will be owned by this new user. I extend accountcontroller.cs register method but i can't set blog properties like blog owner and blog path etc. Sure account view doesn't have blog properties so i want to create a blog dynamically in code. How can I do this? 


var blog = _orchardServices.ContentManager.New<BlogPart>("Blog");

                    _contentManager.Create(blog, VersionOptions.Draft);
                    dynamic model = _contentManager.UpdateEditor(blog, this);


                    var role = _roleService.GetRoleByName("Author");
                    if (role != null)
                            new UserRolesPartRecord
                                UserId = context.User.As<IUser>().Id,
                                Role = role

Nov 30, 2011 at 11:25 PM

blog.As<BlogPart>() ...

There's probably no point running UpdateEditor unless you actually have some POST data that can be picked up by blog creation.

Also, how are you extending the register method? The best way is to write an IUserEventHandler and hook into events like Created or ConfirmedEmail.