Copied to clipboard

Flag this post as spam?

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


  • Kerri Mallinson 113 posts 497 karma points
    Jul 25, 2017 @ 15:01
    Kerri Mallinson
    0

    Getting profile data from members linked with member Picker

    Using Umbraco version 7.6.4

    Hi everyone,

    Would anyone be able to offer some advise regarding the membershipHelper?

    I have 2 types of members, one for Companies and one for Individuals, the Individuals have a member picker property on them so I can select the Company member record they are linked to.

    I'd like to get to the company profile data to show in the view when the individual is logged in. I have done this previously using umbraco.cms.businesslogic but can't figure out a way to do this in the latest version of umbraco.

    Previously i used:

    var individual = umbraco.cms.businesslogic.member.Member.GetCurrentMember();
    
    var companyid = (individual.GetProperty<int>("Company"));
    umbraco.cms.businesslogic.member.Member company = new umbraco.cms.businesslogic.member.Member(companyid);
    

    I can get the Individuals data but i'm not sure of the best way to get the linked companies data, here's the code I have:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Dashboard>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    
        var profileModel = Members.GetCurrentMemberProfileModel();
    
    
    }
    <h1>@Model.Content.Name</h1>
    
    <h2>Get Members Standard Data</h2>
    <p>get members login (UserId) = <strong>@profileModel.UserName</p></strong>
    <p>get members last log in date = <strong>@profileModel.LastLoginDate</p></strong>
    <p>get members email = <strong>@profileModel.Email</p></strong>
    
    <h2>Get Members Profile Data</h2>
    
    @foreach (var mp in profileModel.MemberProperties)
        {
            <p>Property Name: <strong>@mp.Name</strong> / Property Value: <strong>@mp.Value</strong></p>
        }
    
    <h2>Get Members associated Company Profile Data</h2>
    

    Any help would be greatly appreciated.

    Thanks Kerri

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 25, 2017 @ 15:37
    Dennis Aaen
    0

    Hi Kerri,

    Have you tried to use the approach that you will see in this documentation

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Member-Picker

    Hope this helps you a step further.

    /Dennis

  • Kerri Mallinson 113 posts 497 karma points
    Jul 25, 2017 @ 16:02
    Kerri Mallinson
    0

    Hi Dennis,

    My member picker is not on a content page it is on another member type, i'm trying to link 2 members together

    e.g Member 1 has these properties

    • firstname(textstring)
    • surname(textstring)
    • relatedMember(memberPicker)

      Member 2 has this property

    • companyName(textstring)

    when I call @foreach (var mp in profileModel.MemberProperties) I get:

    Property Name: Firstname / Property Value: Test Firstname

    Property Name: Surname / Property Value: Test Surname

    Property Name: Related Member / Property Value: umb://member/d57524fef0554634b3582a93b2ab6215

    I would like to know how to get the member profile for the RelatedMember id (d57524fef0554634b3582a93b2ab6215 in this example)

    Thanks Kerri

  • Kerri Mallinson 113 posts 497 karma points
    Aug 02, 2017 @ 12:38
    Kerri Mallinson
    0

    I've still not figured this one out, can anyone else offer any suggestions?

    Thanks! Kerri

  • MikeD 92 posts 112 karma points
    Aug 28, 2017 @ 14:22
    MikeD
    0

    Does anyone have any more info on this topic? I don't really understand why this change was made in the first place, members were pretty easy to work with before, but now that it is done it would be great if we had some idea how to use it. :D

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Aug 08, 2018 @ 10:06
    Steve Morgan
    2

    Sorry to drag up an old thread - just hit this issue and took me a while to sort so hopefully this will help someone else.

    Member has a picker called "memberPicker" where they pick a linked member. The GetValue returns the Udi - to get the member I needed the guid. This seems to work - if there's a cleaner way let me know!

       var _umbracoMemberService = Services.MemberService;
       var memberPickerValue = curMember.GetValue<GuidUdi>("memberPicker");
       var otherMember = memberPickerValue != null ? _umbracoMemberService.GetByKey(memberPickerValue.Guid) : null;
    
  • Kerri Mallinson 113 posts 497 karma points
    Aug 08, 2018 @ 10:29
    Kerri Mallinson
    100

    Hi Steve,

    We did it by creating a member helper in the end

    using Anon.Models;
    using Umbraco.Web;
    using Umbraco.Web.Security;
    
    namespace Anon.Code
    
    {
        public static class AnonMemberHelper
        {
    
        public static UserData GetUserData(MembershipHelper membershipHelper)
        {
            var currentMember = membershipHelper.GetCurrentMember();
            UserData userData = new UserData();
            if (currentMember != null)
            {
                userData.FirstName = (currentMember.HasProperty("Firstname")
                    ? currentMember.GetProperty("Firstname").Value.ToString()
                    : "");
                userData.Surname = (currentMember.HasProperty("Surname")
                    ? currentMember.GetProperty("Surname").Value.ToString()
                    : "");
                userData.OrganisationId = (currentMember.HasProperty("Organisation")
                    ? int.Parse(currentMember.GetProperty("Organisation").Value.ToString())
                    : 0);
                var companyData = membershipHelper.GetById(userData.OrganisationId);
                userData.UserName = currentMember.Name;
                userData.OrganisationName = companyData.Name;
            }
            return userData;
        }
    
        }
    
    }
    

    Apologies for not sharing previously!

Please Sign in or register to post replies

Write your reply to:

Draft