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.
50 lines
1.7 KiB
50 lines
1.7 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Web;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
|
|
namespace Platform
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly IRepository<User> _userRepo;
|
|
|
|
public UserService(IRepository<User> userRepo)
|
|
{
|
|
this._userRepo = userRepo;
|
|
}
|
|
|
|
public List<string> GetOrgans(string userName)
|
|
{
|
|
var list = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName)
|
|
.SelectMany(o => o.OrganUsers)
|
|
.Select(o => o.OrganId.ToString())
|
|
.ToList();
|
|
return list;
|
|
}
|
|
|
|
public List<Claim> GetRoles(string userName)
|
|
{
|
|
var user = this._userRepo.ReadOnlyTable()
|
|
.Where(o => o.UserName == userName)
|
|
.Include(o => o.OrganUsers).ThenInclude(o => o.Organ)
|
|
.Include(o => o.UserRoles).ThenInclude(o => o.Role).ThenInclude(o => o.RolePermissions).ThenInclude(o => o.Permission)
|
|
.FirstOrDefault();
|
|
List<Claim> list = null;
|
|
if (user != null)
|
|
{
|
|
list = user.UserRoles.Select(o => o.Role)
|
|
.SelectMany(o => o.RolePermissions)
|
|
.Select(o => o.Permission.Number)
|
|
.Select(o => new Claim(ClaimTypes.Role, o))
|
|
.ToList();
|
|
list.Add(new Claim(ClaimTypes.GivenName, user.NickName));
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
}
|