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 1347 posts 1608 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 4899 posts 14655 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 5908 posts 22603 karma points MVP 4x 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 4899 posts 14655 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;
      }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies