using Infrastructure.Data; using Infrastructure.Web; using IoT.Shared.Application.Domain.Entities; using System.Collections.Generic; using System.Linq; using System.Security.Claims; namespace Platform { public class RoleService : IClaimService { private readonly IRepository _userRepo; public RoleService(IRepository userRepo) { this._userRepo = userRepo; } public List GetOrgans(string userName) { return this._userRepo.ReadOnlyTable() .Where(o => o.UserName == userName) .SelectMany(o => o.OrganUsers) .Select(o => o.Organ) .ToList() .Select(o => new Claim("", o.Name)) .ToList(); } public List GetClaims(string userName) { var permissions = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName) .SelectMany(o => o.UserRoles) .Select(o => o.Role) .SelectMany(o => o.RolePermissions) .Select(o => o.Permission.Number) .Select(o => new Claim(ClaimTypes.Role, o)) .ToList(); return permissions; } } }