Copied to clipboard

Flag this post as spam?

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


  • Michael 63 posts 211 karma points
    Nov 28, 2014 @ 14:36
    Michael
    0

    Get membergroup for each member in memberlist

    Hi guys

    I am working on a memberlist. The list works fine. I now need to add some filtering. I have a dropdown where I get all the membergroups. I now want to add the membergroup as a css class on each member. My code looks like this:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @using Umbraco.Core;
    @using Umbraco.Core.Models;
    @using Umbraco.Core.Services;

    @{
      var memberservice = ApplicationContext.Current.Services.MemberService;
    }
    @* -- Bruger JS plugin fra listjs.com til at filtrere -- *@
    <div id="users">
      <input class="search" placeholder="@Umbraco.Field("#Søg efter medarbejder")" />
      <select>
        <option>Vælg en afdeling</option>
        @foreach (var memGroup in Roles.GetAllRoles())
        {
          <option>@memGroup.ToString()</option>
        }
      </select>
      <div class="medarbejdereTH">
        <span><strong>Navn</strong></span>
        <span><strong>Lokal</strong></span>
        <span><strong>Lokal mobil</strong></span>
        <span><strong>Mobil</strong></span>
        <span><strong>Mail</strong></span>
      </div>
      <div class="list medarbejdere">
        @foreach (Member mem in memberservice.GetAllMembers().OrderBy(n => n.Name))
        {
          <div class="">
            <span class="name">@mem.Name</span>
            <span class="lokal">@mem.GetValue("lokal")</span>
            <span class="lokalM">@mem.GetValue("lokalMobil")</span>
            <span class="mobil">@mem.GetValue("medarbejderMobil")</span>
            <span class="mail"><a href="mailto:@mem.Email">@mem.Email</a></span>
          </div>
        }
      </div>
    </div>

    I have been looking at http://our.umbraco.org/documentation/Reference/Management-v6/Services/MemberService

    But I can't figure out what to use.

    How do I go about doing that?

     

    /Michael

  • Dan Lister 416 posts 1974 karma points c-trib
    Nov 28, 2014 @ 15:04
    Dan Lister
    101

    Hi Michael,

    I haven't tested it but you could try the following:

    @foreach (var member in ApplicationContext.Current.Services.MemberService.GetAllMembers().OrderBy(n => n.Name))
    {
        var memberRoles = Roles.GetRolesForUser(member.Username);
    
        // Combine all member roles together, replacing space
        // characters with a hypen
        var memberCss = memberRoles
            .Aggregate(string.Empty, (current, memberRole) => string.Concat(current, memberRole.Replace(" ", "-")));
    
        <div class="@memberCss">
            <span class="name">@member.Name</span>
            <span class="lokal">@member.GetValue("lokal")</span>
            <span class="lokalM">@member.GetValue("lokalMobil")</span>
            <span class="mobil">@member.GetValue("medarbejderMobil")</span>
            <span class="mail"><a href="mailto:@mem.Email">@member.Email</a></span>
        </div>
    }
    

    Hope that helps.

    Thanks, Dan.

  • Michael 63 posts 211 karma points
    Dec 01, 2014 @ 14:03
    Michael
    0

    Hi Dan

    Works like a charm :D

    Thank you very very much.

    /Michael

Please Sign in or register to post replies

Write your reply to:

Draft