예제 #1
0
        public List <PermissionRoleDto> GetPermissionsOfRole(int roleId)
        {
            List <PermissionRoleDto> returnList = new List <PermissionRoleDto>();
            Role role = _roleRepository.Get(roleId);

            foreach (Core.Entities.Permission.Permission p in role.Permissions)
            {
                returnList.Add(new PermissionRoleDto()
                {
                    RoleId       = role.Id,
                    PermissionId = p.Id,
                    IsAllow      = true,
                    IsInherited  = false
                });
            }
            ScanChildRoles(role, role, ref returnList);
            List <Core.Entities.Permission.Permission> permissions = _permissionRepository.GetAllList();

            foreach (Core.Entities.Permission.Permission p in permissions)
            {
                PermissionRoleDto checkItem = returnList.Where(x => x.RoleId == role.Id && x.PermissionId == p.Id)
                                              .FirstOrDefault();
                if (checkItem == null)
                {
                    returnList.Add(new PermissionRoleDto()
                    {
                        RoleId       = role.Id,
                        PermissionId = p.Id,
                        IsAllow      = false,
                        IsInherited  = false
                    });
                }
            }
            return(returnList.OrderBy(x => x.PermissionId).ThenBy(x => x.RoleId).ToList());
        }
예제 #2
0
        public void SaveSecuritySchema(List <PermissionRoleDto> permissionRoleDtos)
        {
            List <PermissionRoleDto> allowedList = permissionRoleDtos.Where(x => x.IsInherited == false && x.IsAllow == true).ToList();
            List <Role> roles = _roleRepository.GetAllList(x => x.IsDeleted == false);
            List <Core.Entities.Permission.Permission> permissions = _permissionRepository.GetAllList();

            foreach (Role r in roles)
            {
                var rolePermissions = r.Permissions;
                foreach (Core.Entities.Permission.Permission p in permissions)
                {
                    PermissionRoleDto pr = allowedList.Where(x => x.PermissionId == p.Id && x.RoleId == r.Id).FirstOrDefault();
                    if (pr != null && !rolePermissions.Contains(p))
                    {
                        rolePermissions.Add(p);
                        continue;
                    }
                    if (pr == null && rolePermissions.Contains(p))
                    {
                        rolePermissions.Remove(p);
                        continue;
                    }
                }
                _roleRepository.Update(r);
            }
        }
        public static PermissionRoleDto Map(PermissionRole entity)
        {
            var dto = new PermissionRoleDto();

            dto.Id         = entity.Id;
            dto.Permission = entity.Permission != null?PermissionDtoMapper.Map(entity.Permission) : null;

            dto.CreatedOn      = entity.CreatedOn;
            dto.LastModifiedOn = entity.LastModifiedOn;
            dto.Deleted        = entity.Deleted;
            //todo: don't do LastModifiedBy in here, have a 'MapWithLastModifiedBy' method - otherwise infinately recursive call.
            //todo: don't do CreatedBy in here, have a 'MapWithCreatedBy' method - otherwise infinately recursive call.
            return(dto);
        }