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> GetFeaturePermissionByEmployeeID(int EmployeeID) { List 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> GetFeaturePermissionByRoleID(Guid roleId) { List 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; } } }