Creating a list via code

Topics: Customizing Orchard, Writing modules
May 2, 2011 at 1:06 PM

I am attempting to create a list via code and I am at a lost as to how to attach parts to the list once its been created.

Here is what I have so far.

      var courseList = _contentManager.New("List");

      courseList.As<ICommonPart>().Owner = _membershipService.GetUser("admin");
      courseList.As<RoutePart>().Slug = "CourseList";
      courseList.As<RoutePart>().Path = "CourseList";
      courseList.As<RoutePart>().Title = "Course-List";

      courseList.As<ContainerPart>().Record.ItemContentType = "Course";
      courseList.As<ContainerPart>().Record.PageSize = 10;
      courseList.As<ContainerPart>().Record.Paginated = true;
      courseList.As<ContainerPart>().Record.OrderByProperty = "CreatedUtc";
      courseList.As<ContainerPart>().Record.OrderByDirection = 0;               

      courseList.As<MenuPart>().OnMainMenu = true;
      courseList.As<MenuPart>().MenuPosition = _menuService.Get().Select(menuPart => menuPart.MenuPosition).Max() + 1 + ".0";
      courseList.As<MenuPart>().MenuText = "Course List";

      _contentManager.Create(courseList);

At this point how do I add content parts to the list?

May 2, 2011 at 1:40 PM

 

item.As<CommonPart>().Record.Container = targetContainer.ContentItem.Record;

I found it.