Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eric Patton 8 posts 28 karma points
    Dec 31, 2015 @ 01:34
    Eric Patton
    0

    Get name of member who last published a content node

    I'm making an event to shoot information to Slack whenever content is published. I've got it all hooked up and working fine, but I'm having trouble figuring out how to get the name of the member who did the publish.

    This is my code that's not working (returning null on the member when I try to get the Name property):

    void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
    {
        foreach (var entity in e.PublishedEntities)
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
            var memberWhoEdited = umbracoHelper.TypedMember(entity.WriterId);
            var memberText = memberWhoEdited.Name; //Fails at this line when trying to access the Name property
        }
    }
    

    Any ideas what the issue might be?

    Edit: Or how to actually accomplish this.

  • Eric Patton 8 posts 28 karma points
    Dec 31, 2015 @ 01:46
    Eric Patton
    0

    It looks like the WriterId is always 0.

    This page says that the WriterId should be the correct property, so I'm guessing it just either doesn't work or I need to do something in order to set it up to work. Does anyone know?

  • keilo 568 posts 1023 karma points
    Dec 31, 2015 @ 06:41
    keilo
    0

    Hi Eric

    Which (sub)version of Umbraco 7 are you using?

  • Eric Patton 8 posts 28 karma points
    Dec 31, 2015 @ 17:00
    Eric Patton
    0

    I'm using 7.2.8

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jan 01, 2016 @ 12:57
    Andy Butland
    0

    First thing I think is that it looks like you have a confusion between members and users. Members are people that may register login to the front-end of your website, if you have that feature. Users are the people that log into the back-office to make amends.

    As to the finding the logged in user, have a look at this answer in a previous thread - looks to me that should work for you.

  • keilo 568 posts 1023 karma points
    Jan 02, 2016 @ 08:17
    keilo
    0

    It seems you are sending the userid (author id) to the member service?

    How about using

    memberText  = HttpContext.Current.User.Identity.Name;
    

    or to get id:

    var userService = ApplicationContext.Current.Services.UserService;
    
    var memberWhoEdited = userService.GetByUsername(HttpContext.Current.User.Identity.Name).Id;
    
  • Charles Afford 1163 posts 1709 karma points
    Jan 02, 2016 @ 13:58
    Charles Afford
    0

    Where you have gone wrong is you are getting the member and not the user.

    The User is the backend and the Member is the front end

    All you need to do is use the UserService and pass in the WriteId into a method GetUserById (something like that)

    Charlie :)

Please Sign in or register to post replies

Write your reply to:

Draft