Base solution for your next web application
Open Closed

Best way to extend UserManager #7359


User avatar
0
rvanwoezik created

I have added an external Id to users: SomId. Now i want to add a GetUserBySomId(int somId)

What is the best Zero way to do that?

Thanks in advance, Rene van Woezik

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    src\MyCompanyName.AbpZeroTemplate.Core\Authorization\Users\UserManager.cs

    You can define the method directly in the UserManager.

    Then inject the UserManager elsewhere and call the relevant methods.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    rvanwoezik created

    Hi @maliming, thanks for your quick reply. Shoud i use the IRepository<User, long> in my method to find the user??

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    maliming created
    Support Team

    The UserManager constructor injects some services, such as UserStore. You can use them directly, There are also many methods in the base class that you can use.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    rvanwoezik created

    Thnx! This is wat i have done in UserManager.cs:

    public User GetUserBySomId(int somId) { return Users.FirstOrDefault(u => u.SpotOnMedicsId == somId); } And it works

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    maliming created
    Support Team

    I suggest you use [UnitOfWork] for your method.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)