Copied to clipboard

Flag this post as spam?

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


  • Steve 140 posts 321 karma points
    Mar 25, 2015 @ 18:02
    Steve
    0

    possible to use 'Member' as model for WebApi Controller?

    I'd like to use a WebApi to look up members by role (got it working) and wondering if I can return the list of members directly rather than use a custom made model.

    Method in the controller:

     public IEnumerable<Member> GetUsersInRole(string memberType)

            {

                return Services.MemberService.GetMembersInRole(memberType).Cast<Member>().ToArray();

     

            }

    However getting an exception message: No set method for property 'ContentTypeAlias' in type 'Umbraco.Core.Models.Member'.

    If possible, I'd like to avoid creating a model just to map all of the member properties into a new object.

    thanks for any advice which might help.

    Steve

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 25, 2015 @ 18:10
    Jeroen Breuer
    0

    Hello,

    I don't know why it's not working, but you shouldn't use the Member object for this. It's not cached. You should return an IPublishedContent. More info: http://issues.umbraco.org/issue/U4-4379

    Jeroen

  • Steve 140 posts 321 karma points
    Mar 25, 2015 @ 18:36
    Steve
    0

    Thanks Jeroen. I now receive an exception 'Unable to cast object of type 'Umbraco.Core.Models.Member' to type 'Umbraco.Core.Models.IPublishedContent'.'

    Should I not use the memberserice.getmembersinrole method?

    Could you let me know how to select the members by role as IPublishedContent?

    Steve

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 26, 2015 @ 09:09
    Jeroen Breuer
    0

    Hello,

    I haven't used the member helpers a lot. In the link I provided above should be some examples. However it could be possible that the method your looking for doesn't exist yet. For 7.2.5 there is this feature: http://issues.umbraco.org/issue/U4-6368.

    Jeroen

  • Steve 140 posts 321 karma points
    Mar 26, 2015 @ 15:14
    Steve
    0

    Hello Jeroen,

    Thanks for sending this link - it appears there are plans to add more methods to the MembershipHelper.

    If I use the MemberService.GetMembersInRole method and return a custom model rather than a Member object would I avoid the downside of the Member object not being cached?

    I'm looking for the most efficient way to query members and return the selected data - just can't determine what that is.

    thanks,

    Steve

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 26, 2015 @ 15:17
    Jeroen Breuer
    0

    The member service is used for editing data and not for fetching data. So it's always slower. You should always try to return the data as an IPublishedContent, but I'm not sure if those methods are available yet.

    Jeroen

  • Steve 140 posts 321 karma points
    Mar 26, 2015 @ 15:42
    Steve
    0

    Yes, the speed is indeed the issue with our current implementation. It is slow, and it is the reason we are trying to utilize the WebApi and use AJAX to load sections of the member list based on the users geographic location.

    I will try it with the MemberService and check the speed. If it is not a big improvement, I will make a new Document Type to store the needed Member information keep it synchronized with Member data with some kind of code. 

    Thanks again for your help.

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft