Esempio n. 1
0
 public void Add(Guid unitId, string roleName, string roleCode, string description)
 {
     var role = new Role();
     role.Name = roleName;
     role.Code = roleCode;
     role.Description = description;
     role.UnitId = unitId;
     _roleRepository.Save(role);
 }
 public void AssignRole(RoleUser roleUser, Role role)
 {
     roleUser.Roles.Add(role);
 }
Esempio n. 3
0
 private void InitUnitPermissions(Unit unit, User admin)
 {
     var privilegeRepository = new PrivilegeRepository();
     var privileges = privilegeRepository.GetAllPrivileges();
     var roleRepository = new RoleRepository();
     var roles = roleRepository.GetAllRoleByUnitId(unit.Id);
     var role = roles.FirstOrDefault(r => r.Code == "SuperAdmin");
     if (role == null)
     {
         role = new Role();
         role.Name = "超级管理员";
         role.Code = "SuperAdmin";
         role.UnitId = unit.Id;
         privileges.ToList().ForEach(privilege => role.Privileges.Add(privilege));
         roleRepository.Save(role);
     }
     var roleUserRepository = new RoleUserRepository();
     var roleUser = roleUserRepository.GetRoleUserByUserId(admin.Id);
     if (roleUser == null)
     {
         roleUser = new RoleUser();
         roleUser.UserId = admin.Id;
         roleUser.Roles.Add(role);
         roleUserRepository.Save(roleUser);
     }
 }