Development of the widget that display information about the user

Topics: Customizing Orchard, General
Apr 30, 2014 at 10:09 AM
I would like to create a simple widget that display information about the user that published Blog or Blog Post. The widget should be located next to user’s Blog Post. I would like to display some of the fields that are attached to the Content Definition User. For example the widget should contain user’s full name and some description that he wrote about himself.

Please is it possible to do so by adding some code to the widget or do I have to create a new module?

I am using Profile module to allow user to modify his details (User fields) but my question is not related to this module.

Thank you very much...
Apr 30, 2014 at 7:51 PM
Just out of curiosity, since you're using the Profile module, why not allow the functionality using the existing module? If you added a field to the User Profile to hold this information, you can look up the username of the blog author using @Model.ContentItem.CommonPart.Owner.UserName, create a user object, then get the ProfilePart and access the field you created. You can get the user object from the username using
        var cm = WorkContext.Resolve<IContentManager>();
        var user = cm.Query<UserPart, UserPartRecord>().Where(x => x.NormalizedUserName == Model.ContentItem.CommonPart.Owner.UserName).List().FirstOrDefault();
then you can get to the ProfilePart using @user.ProfilePart.NewField.value or something along those lines. I pieced that together from several different pieces of code, so there might be an easier way, but I would definitely consider using the Profile module for this if you can.
May 1, 2014 at 7:55 PM
Edited May 1, 2014 at 7:55 PM
thank you very much for the answer. I created my first module and widget (I used documentation Writing a Content Part and Writing a Widget) and everything worked great until I pasted the last piece of your code:
Error: 'Orchard.Users.Models.UserPart' does not contain a definition for 'ProfilePart' and no extension method 'ProfilePart' accepting a first argument of type 'Orchard.Users.Models.UserPart' could be found (are you missing a using directive or an assembly reference?)

SomeText exists and contain text string and of course I added all "using" and all required references (Orchard.Profile and Orchard.Users). Please do you have some example project? Thank you.
May 1, 2014 at 9:52 PM
ProfilePart is the part that is created by the Profile module and attached to the User type. I was under the impression that you were modifying one of the blog shapes to display this information. If you have a custom module that you are using, can you post some of the code for that so we can see what it looks like? Thanks.