Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1461 posts 1883 karma points
    Aug 03, 2015 @ 12:34
    Gordon Saxby
    0

    UserService equivalent of user.getAll

    Is there an equivalent of

    var editors = umbraco.BusinessLogic.User.getAll().Where(u => u.UserType.Alias == "editor");

    via the UserService? Visual Studio is telling me that "umbraco.BusinessLogic.User" is obsolete and to use UserService instead.

    There is a "getAll()" but it returns a paged list, which is not what I want (I don't think)!?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 03, 2015 @ 13:43
    Sebastiaan Janssen
    0

    If you want all of them you make the page size as large as you can:

            var userService = Services.UserService;
            var totalUsers = 0;
            var allUsers = userService.GetAll(0, int.MaxValue, out totalUsers);
    

    Depending on the number of users you have this may or may not perform well.. ;-)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 03, 2015 @ 14:42
    Alex Skrypnyk
    0

    Hi Sebastian,

    Should we copy service instance each time ? Can we use Services.UserService ?

    Thanks, Alex

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 03, 2015 @ 15:16
    Sebastiaan Janssen
    0

    Not sure what you mean? The UsersService is a getter and can be used just about anywhere, you might need to find it in the UmbracoContext:

    var usersService = UmbracoContext.Application.Services.UserService;
    

    Goes to this code in Umbraco.Core.Services.ServiceContext:

    /// <summary>
    /// Gets the <see cref="P:Umbraco.Core.Services.ServiceContext.UserService"/>
    /// </summary>
    public IUserService UserService
    {
      get
      {
        return this._userService.Value;
      }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft