54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
|
|
|
|
using Marco.Pms.DataAccess.Data;
|
|
using Marco.Pms.Model.Entitlements;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MarcoBMS.Services.Helpers
|
|
{
|
|
public class RolesHelper
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
public RolesHelper(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<List<FeaturePermission>> GetFeaturePermissionByEmployeeID(int EmployeeID)
|
|
{
|
|
List<Guid> roleMappings = await _context.EmployeeRoleMappings.Where(c => c.EmployeeId ==EmployeeID && c.IsEnabled == true).Select(c=>c.RoleId).ToListAsync();
|
|
|
|
// _context.RolePermissionMappings
|
|
|
|
var result = await (from rpm in _context.RolePermissionMappings
|
|
join fp in _context.FeaturePermissions.Where(c=>c.IsEnabled == true).Include(fp => fp.Feature) // Include Feature
|
|
on rpm.FeaturePermissionId equals fp.Id
|
|
where roleMappings.Contains(rpm.ApplicationRoleId)
|
|
select fp)
|
|
.ToListAsync();
|
|
|
|
return result;
|
|
|
|
// return null;
|
|
}
|
|
|
|
public async Task<List<FeaturePermission>> GetFeaturePermissionByRoleID(Guid roleId)
|
|
{
|
|
List<Guid> roleMappings = await _context.RolePermissionMappings.Where(c => c.ApplicationRoleId == roleId ).Select(c => c.ApplicationRoleId).ToListAsync();
|
|
|
|
// _context.RolePermissionMappings
|
|
|
|
var result = await (from rpm in _context.RolePermissionMappings.Where(c=>c.ApplicationRoleId == roleId)
|
|
join fp in _context.FeaturePermissions.Where(c => c.IsEnabled == true).Include(fp => fp.Feature) // Include Feature
|
|
on rpm.FeaturePermissionId equals fp.Id
|
|
select fp)
|
|
.ToListAsync();
|
|
|
|
return result;
|
|
|
|
// return null;
|
|
}
|
|
|
|
}
|
|
}
|