Copied to clipboard

Flag this post as spam?

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


  • Pete 18 posts 219 karma points
    1 day ago
    Pete
    0

    Member group picker save text instead of id

    I am trying to validate some member groups from the current user against the groups selected in a component but I have an issue as the groups are returned as the string names from the memberManager.GetRolesAsync, where as they are returned as the ids from the component member group picker

    Is there a way to either get the role ids from the member manager or the string names from the group picker? I see I can loop through the ids and get the names using the content service, but that seems really inefficient as all I want to do is match the two lists using an intersect

    Also why does the member group picker return ids when all the member service and manager methods take the string name. It just seems really stupid

  • Pete 18 posts 219 karma points
    1 day ago
    Pete
    100

    Seems a bit clunky but in the end I have done this (I think one call to the member service is better than multiple to the content service)

    var allRoles = memberService.GetAllRoles();
    var roles = Model.Content.Value<string>("roles").Split(',');
    var roleNames = allRoles.Where(r => roles.Contains(r.Id.ToString())).Select(r => r.Name ?? string.Empty);
    

    If anyone has a better solution (like a member group picker that stores group names instead of ids), please feel free to post your answer

Please Sign in or register to post replies

Write your reply to:

Draft