This project is read-only.

One to Many List in a Content Part Template

Topics: Writing modules
Feb 14, 2012 at 8:32 AM
Edited Feb 14, 2012 at 8:36 AM

Let just simply state what I am attempting to do, where I stand & where I'm stuck (new to Orchard, loving it up until about right now)

I am creating a admin review based module where from the backend a user can create

1. Create a Review Content
2. Set details such as the name of the review 
3.  Select a category for the Review (this populates the proper measurements within the ReviewPart) (ie Vehicle Review - will create "Handling", "Powertrain", "Styling" etc)
4. Set the grades for these reviews.

I have found this great resource...on the docs.... & it has helped tremendously...but nowhere have I seen an example where there are a multiple related item list updated through the editor template where the list can grow/shrink.

Here is where I stand I have completed the first 3 tasks no problem. but have been stuck on #4 all day. Its a simple issue that I could knock out in MVC controller/view in no time, however I can't quite get there with the Orchard Driver/content part/dynamic shape paradigm.

Here is a brief overview.....


public class ReviewPartRecord : ContentPartRecord {
....public virtual IList<ReviewScoreRecord> Scores { get; set; }...


public class ReviewPart : ContentPart<ReviewPartRecord>  {
.... public IEnumerable<ReviewScoreRecord> Scores {            get { return Record.Scores.AsEnumerable(); }....

  public class ReviewScoreRecord    { ....     
public virtual string MeasurementName { get; set; } 
public virtual decimal Score{ get; set; } 
.... }

   protected override DriverResult Editor(ReviewPart part, IUpdateModel updater, dynamic shapeHelper) {
            int previousCategory = part.ReviewCategoryRecordId;
            updater.TryUpdateModel(part, Prefix, null, null);
            if (previousCategory != part.ReviewCategoryRecordId) _reviewService.UpdateScoreRecordsForCategory(part.Record);

HERE IS WHERE I NEED TO PERSIST THE CHANGES TO part->scores ARGGGHHHH!!! JUST WORK!!!! return Editor(part, shapeHelper); }


In the driver above, the ReviewPart gets updated, the reviewservice adds and removes the proper score records when/if the category changes.

How do I  persist the scores from the ReviewPart->IList<ReviewScoreRecord>->Score?  ... Time for sleep.... :)


Feb 14, 2012 at 8:54 AM

The record shouldn't hold a list. You should re-read the tutorial. The n-n part has everything you need.