public async Task <IList <GetUserPermissionsModel> > Handle(GetUserPermissionsQuery request, CancellationToken cancellationToken) { var authUserId = UserHelper.AuthId(); var user = await _context.Users .AsNoTracking() .Include(x => x.UserRoles) .ThenInclude(x => x.Role) .ThenInclude(x => x.RoleHasPermissions) .ThenInclude(x => x.Permission) .FirstOrDefaultAsync(x => x.Id == authUserId); return(user.UserRoles .SelectMany(x => x.Role.RoleHasPermissions) .Select(x => new GetUserPermissionsModel { Id = x.Permission.Id, Name = x.Permission.Name }).ToList()); }
public async Task <IActionResult> GetUserPermissions([FromQuery] GetUserPermissionsQuery query) { var result = await Mediator.Send(query); return(Ok(result)); }