2
votes

I can't seem to store additional data in a separate contentpart attached to User. I have done the following:

  • Created a module
  • In the module I created a Model for ProfilePart and ProfilePartRecord
  • In the migration I created a table for ProfilePartRecord (from type ContentPartRecord)
  • In the migration I altered the typedefinition for User, by setting WithPart ProfilePart
  • I created a driver class, that has 2 edit methods, one for get and one for post (code snippets are below
  • I also created a handler that adds a storage filter for profilePartRepository of type ProfilePartRecord

Module Structure

  • Drivers/ProfilePartDriver.cs
  • Handlers/ProfileHandler.cs
  • Models/ProfilePart.cs
  • Models/ProfilePartRecord.cs
  • Views/EditorTemplates/Parts/profile.cshtml
  • Migrations.cs
  • Placement.info

Since I think the issue is in the Driver. This is my code:

Is it going wrong because the part is attached to User? Or am I missing something else.

public class ProfilePartDriver:ContentPartDriver {

protected override string Prefix
{
    get { return "Profile"; }
}

//GET
protected override DriverResult Editor(ProfilePart part, dynamic shapeHelper)
{
    return ContentShape("Parts_Profile_Edit", () => 
                    shapeHelper.EditorTemplate(TemplateName: "Parts/Profile", Model: part, Prefix: Prefix));
}

//POST
protected override DriverResult Editor(ProfilePart part, IUpdateModel updater, dynamic shapeHelper)
{
    updater.TryUpdateModel(part, Prefix, null, null);
    return Editor(part, shapeHelper);
}

}

2
I'd look at one of the existing profile modules and see how they do it.Bertrand Le Roy

2 Answers

2
votes

I have used Skywalker's blog. There is one chapter about registering customers by using the User and adding your own content parts to it. Worked nice for me.

0
votes

First of all - is your ProfilePart editor shown at all when you go to Dashboard and edit a given user? I noticed you're using Parts_Profile_Edit as a shape key, but actually use EditorTemplates/Parts/Profile.cshtml as a template. It's perfectly correct, but note that Placement.info file uses shape keys, so you have to use Parts_Profile_Edit as a shape name in there. Otherwise it won't get displayed.

Second - have you tried debugging to see if the second driver Editor method (the one for handling POST) is being called at all?

Like Bertrand suggested, I'd look into one of the existing modules that work (afaik there is one for user profile in the Gallery) and see the difference. It might be something small, eg. a typo.