Some help with Editing a Users extened profile from the frontend?

Topics: Writing modules
Jun 18, 2014 at 9:23 AM
Hey guys, I've been using Contrib.Profile [Stanley Goldman edition ;) - link
] as a bit of guide [not implemented, just reviewing the code] to allow the logged in user the ability to edit their profile from the frontend. In my experiment case, I have attached/extended the User Record with a Profile Record [currently it just has two fields for testing].

MIGRATION:

            SchemaBuilder.CreateTable("ProfilePartRecord",
                table => table
                    .ContentPartRecord()
                    //ProfilePartRecord_id [Auto Key]
                    .Column<string>("FirstName")
                    .Column<string>("LastName")
                    //System
                    .Column<DateTime>("CreatedAt")
                );

            ContentDefinitionManager.AlterTypeDefinition("Profile", t => t
                .WithPart(typeof(ProfilePart).Name)
                .WithPart("UserPart")
                );

            ContentDefinitionManager.AlterTypeDefinition("User", t => t
                .WithPart("ProfilePart")
                );
The question is, I'm a little perplexed as to how/what's the best way to access the two extended field's data for editing in relation to the Contrib.Profile 'Edit' action:
 public ActionResult Edit()
        {
            if (_orchardServices.WorkContext.CurrentUser == null)
            {
                return HttpNotFound();
            }

            IUser user = _orchardServices.WorkContext.CurrentUser;

            dynamic shape = _orchardServices.ContentManager.BuildEditor(user.ContentItem);

            return View((object)shape);
        }
obviously the above gets the ORchard.Security IUser models username & email, but I need to acquire the related Firstname, Lastname from the Profile Record as well. Is this a matter of getting the CurrentUsers ID key, querying the DB for the related Profile -- or is there a better methodology? Thanks in advance, Cheers Ron
PS> I looked into the Hungary.Demo AdminController which got me quite confused with orchard's way of doing things; I'm clearly inexperienced.
Jun 19, 2014 at 8:00 AM
Ok, so I butchered my driver and made a few other changes which seemed to work. I have to clean-up my code, then i'm sure I will have some more questions - thanks guys.
        public ActionResult Edit()
        {
            if (_orchardServices.WorkContext.CurrentUser == null)
            {
                return HttpNotFound();
            }

            IUser user = _orchardServices.WorkContext.CurrentUser;

            var profile = _orchardServices.ContentManager.Get(user.Id);

            dynamic shape = _orchardServices.ContentManager.BuildEditor(profile);

            return View((object)shape);
        }