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/labs/Teacher/TeacherExt/UserService.cs

49 lines
2.0 KiB

using Infrastructure.Data;
using Infrastructure.Web;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using TeacherExt.Entities;
namespace TeacherExt
{
public class UserService : IUserService
{
private readonly IRepository<Person> _personRepo;
private readonly IRepository<PersonLogin> _loginRepo;
private readonly IRepository<PersonRole> _personRoleRepo;
private readonly IRepository<SystemRole> _roleRepo;
public UserService(IRepository<Person> personRepo,
IRepository<PersonLogin> loginRepo,
IRepository<PersonRole> personRoleRepo,
IRepository<SystemRole> roleRepo)
{
this._personRepo = personRepo;
this._loginRepo = loginRepo;
this._personRoleRepo = personRoleRepo;
this._roleRepo = roleRepo;
}
public List<string> GetOrgans(string userName)
{
return new List<string>();
}
public List<Claim> GetRoles(string userName, string organId)
{
var list = (
from loginPerson in this._loginRepo.ReadOnlyTable().Where(o=>o.LoginName==userName)
join personRole in this._personRoleRepo.ReadOnlyTable() on loginPerson.PersonId equals personRole.PersonId
join role in this._roleRepo.ReadOnlyTable() on personRole.RoleId equals role.Id
select role.RoleName).Distinct().ToList()
.Select(o => new Claim(ClaimTypes.Role, o)).ToList();
var obj = (from loginPerson in this._loginRepo.ReadOnlyTable().Where(o => o.LoginName == userName)
join person in this._personRepo.ReadOnlyTable() on loginPerson.PersonId equals person.Id
select new { person.Id, person.OrganId }).FirstOrDefault();
list.Add(new Claim("PersonId", obj.Id.ToString()));
list.Add(new Claim("OrganId", obj.OrganId.ToString()));
return list;
}
}
}