Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check user roles from Application Service

i'm implementing Application Service that sends statistical data to home page (dashboard application page).

Based on User's Role (the service needs authentication) i would extract/aggregate data from database using WhereIf() based on is role

In particular if user is administrator, I will not apply a data extraction filter using WhereIf()

To do that i've injected IAbpSession inside service constructor to be able to give userid, but how can i ckeck if user is an administrator?

like image 524
Saro Avatar asked Dec 11 '22 09:12

Saro


1 Answers

You can check if current user is an administrator by checking the associated roles of that user. You must inject the UserManager which has several methods for role checking. One of them is IsInRole(userId, roleName).

like image 91
Richard Brink Avatar answered Jan 25 '23 05:01

Richard Brink