Retrieve Part values during events in handler

Topics: Customizing Orchard, Troubleshooting
Jul 3, 2015 at 7:51 AM

I created a module that adds some fields in the user creation form. In my handler, I would like to retrieve the values of these fields, but I can't seem to get them. I've tried on several events (OnCreated, OnUpdated, OnPublished,...) but everytime, the properties of my part object are null.
The values are correctly persisted in the repository though... Do I miss something? I have followed the tutorial on orchardproject.

Jul 6, 2015 at 3:10 PM
So you added a content part and that does get properly persisted but is not filled in these events? Can you share your handler code?
Jul 10, 2015 at 9:39 AM
Here is part of the code :
private readonly IClientAppBLL _clientAppBll;
private readonly INotifier _notifier;
private readonly IOrchardServices _orchardServices;
private Localizer T;
private readonly IMailService _mailService;
private readonly ISecurityBLL _securityBll;
private readonly IMembershipService _membershipService;

public GenealexUserHandler(IRepository<GenealexUserRecord> repository,
        IClientAppBLL clientAppBll,
        INotifier notifier,
        IOrchardServices orchardServices,
        IMailService mailService,
        ISecurityBLL securityBll,
        IMembershipService membershipService
            _clientAppBll = clientAppBll;
            _notifier = notifier;
            _orchardServices = orchardServices;
            _mailService = mailService;
            _securityBll = securityBll;
            _membershipService = membershipService;
            T = NullLocalizer.Instance;

            OnCreated<GenealexUserPart>((context, part) => Created(context, part));
            //OnUpdated<GenealexUserPart>((context, part) => Updated(context, part));

 public void Created(CreateContentContext context, GenealexUserPart part)
            if (CheckIfUserIsAllowedToBeActive(context.ContentItem, false))
                UserPart userPart = (UserPart)context.ContentItem.Parts.FirstOrDefault(cp => cp is UserPart);
                //Set the generated password before sending the email
                string password = _securityBll.GeneratePassword(userPart.Email, userPart.UserName);
                userPart.PasswordFormat = MembershipPasswordFormat.Hashed;
                _membershipService.SetPassword(userPart, password);
                //TODO : Find how we can retrieve, at that point, the values stored in GenealexUserPart.
                //SendMailWhenUserIsCreated(context, password);

public bool CheckIfUserIsAllowedToBeActive(ContentItem contentItem, bool isUpdate)
              return true; 
During the Created event, before sending an e-mail, I would like to retrieve the fields value in the GenealexUserPart (containing a last name, a first name and a default culture). But I just have null values.

I've tried in Updated and Published events with no luck.
Jul 10, 2015 at 11:44 AM
Ah, probably it's because users are updated a bit differently then normal content items. I suggest you to check out the events of IUserEventHandler and hook into that instead of content events.
Jul 23, 2015 at 8:51 AM
the events from IUserEventHandler also can not get data from the custom module and custom content part. Is there other way in Orchard to get data from custom content part?