You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Platform/RoleService.cs

43 lines
1.4 KiB

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<User> _userRepo;
public RoleService(IRepository<User> userRepo)
{
this._userRepo = userRepo;
}
public List<Claim> 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<Claim> 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;
}
}
}